停止并重新启动线程(Stopping and Restarting a Thread)
我试图阻止当前线程,更改run()方法,然后重新启动该线程。 我环顾四周,大多数方法都被弃用了。 但是,interrupt()不是。 我不确定你是否需要这么做。
interrupt(); start();
这对我需要它做什么有用吗? 它说你不应该多次启动一个线程,我不知道它是否意味着
start(); start();
而不是我想做的事。
任何帮助表示赞赏。
谢谢
I am trying to stop a current thread, change the run() method, and then restart that thread. I've looked around, and most of the methods are deprecated. However, interrupt() is not. I'm not sure if that's all you need to do.
interrupt(); start();
Would that work for what I needed it to do? It says that you should never start a thread more than once, and I don't know if it means
start(); start();
Rather than what I wanted to do.
Any help is appreciated.
Thanks
原文:https://stackoverflow.com/questions/8655861
最满意答案
只要找到一些东西就添加到路径中:
… if (data.children != null) { for (let i = 0; i < data.children.length; i++) { let result = this.search(data.children[i], name); if (result) { result.unshift("children", i); // or whatever you want in your path return result; } } }
Just add to the path once you've found something:
… if (data.children != null) { for (let i = 0; i < data.children.length; i++) { let result = this.search(data.children[i], name); if (result) { result.unshift("children", i); // or whatever you want in your path return result; } } }
相关问答
更多-
var tree = [{ name: "Insights", nodeId: "tree-node-0" }, { name: "Level1", nodeId: "tree-node-1", parentId: "tree-node-0" }, { name: "Level2", nodeId: "tree-node-2", parentId: "tree-node-1" }, { name: " ...
-
如何根据叶子值显示JSON树中的特定路径?(How to display a specifc path from JSON tree depending on the leaves values?)[2023-07-02]
您可以使用递归来循环对象。 使用Array.isArray测试value是否为Array类型, typeof(obj)==="object"表示对象。 注意: typeof(obj)将返回Array和Object function searchInObj(obj, value, result) { // check for array and call for every item if (Array.isArray(obj)) { // primary flag ... -
JavaScript在行走JSON树时更改路径[重复](JavaScript change the path when walking a JSON tree [duplicate])[2023-09-20]
tree.newPath在树对象中查找名为“newPath”的键 使用这样的函数来获得所需的节点: function getNodeByPathString(path) { var node = tree; var partsOfPath = path.split('.'); while(let part = partsOfPath.shift()) node = node[part]; return node; } tree.newPath looks for a key wit ... -
只要找到一些东西就添加到路径中: … if (data.children != null) { for (let i = 0; i < data.children.length; i++) { let result = this.search(data.children[i], name); if (result) { result.unshift("children", i); // or whatever you want in your ...
-
你的代码有几个问题,但你得到的“错误”不是错误; 它是由path(tree, 0)返回的值,它是一个生成器。 您需要将其包装在list()以强制它自己进行评估。 也就是说,如果你这样做,你会遇到几个错误。 即使你修复了表面的bug,你的代码也不会给你想要的结果。 这段代码将完成你想要做的事情: import pprint def paths(tree): if not tree['children']: yield (tree['id'],) else: ...
-
您可以使用迭代和递归方法提供下一个递归的实际路径。 如果找到了一个末端节点,那么一个新的对象被推送到带有被访问节点的结果数组中。 function getPath(object) { function iter(o, path) { Object.keys(o).forEach(function (k) { if (typeof o[k] === 'object') { return iter(o[k], path. ...
-
您可以尝试这样的算法: public JSONObject toJSON(Node node, List
others) { JSONObject json = new JSONObject(); json.put("id", node.id); // and so on ... List children = new ArrayList (); for(Node subnode : others) { if(isCh ... -
您将需要数组索引,因此您可以在for-of之外跟踪它,然后在路径上使用它,或者使用Array#some (或者使用无聊的旧代码)。 这里跟踪了for-of之外的索引 - 我还添加了一个我认为可能非常重要的else :-) _findInTree = (id, tree, path = "") => { let result; let index; let rv; if (tree.id === id) { result = tree; } else { ...
-
Nginx返回路径的文件(Nginx return file for path)[2023-01-22]
使用index指令将r.json命名r.json位置的默认文件名: location /r/ { index r.json; alias /home/user/media/json/; } Use the index directive to name r.json as the default filename within that location: location /r/ { index r.json; alias /home/user/media/json/; ... -
在每个递归调用创建新范围时,尝试跟踪本地范围变量中的路径将不起作用。 假设你想要的东西与你已经非常相似,那么一个相当小的变化就是使索引的查找路径成为方法的返回值。 递归调用的基本情况(当没有子节点时)返回[] (找到)或null (未找到)。 var tree = function(struct, cmp) { if (struct === cmp) { // `cmp` is found at current `struct`. return []; } e ...