你好,我想知道是否有一种方法可以调用函数/方法(最好是Python或Java)并继续执行而不等待它。
Example:
def a():
b() #call a function, b()
return "something"
def b():
#something that takes a really long time
在新线程中运行它。了解java中的多线程here http://www.tutorialspoint.com/java/java_multithreading.htm和Python多线程here http://www.tutorialspoint.com/python/python_multithreading.htm
Java 示例:
错误的方式......通过子类化 Thread
new Thread() {
public void run() {
YourFunction();//Call your function
}
}.start();
正确的方法...通过提供 Runnable 实例
Runnable myrunnable = new Runnable() {
public void run() {
YourFunction();//Call your function
}
}
new Thread(myrunnable).start();//Call it when you need to run the function
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)