几乎同时进行两个循环
我不知道这个过程叫什么,但我发现这是可能的。 这个过程叫什么?
基本上,我有一个有循环的方法,并且在每次迭代中都有一个延迟秒。
function myLoop(float delay)
{
for(int x=0; x<100; x++)
{
Print("Loop number: " + x);
TimeDelay(delay);
}
}
我想运行第二个实例而不等待第一个实例完成。
function main()
{
myLoop(2);
myLoop(2);
}
所以一旦第一个 myLoop 启动,我希望第二个 myLoop 立即启动,它们将同时运行,我的问题是,你怎么称呼这个过程? 这个过程可能吗?(例如在java中)。
非常感谢! :)
i don't what this process is called, but i've seen that it's possible.
what is this process called?
basically, i have a method that has a loop, and in every iteration has a delay second.
function myLoop(float delay)
{
for(int x=0; x<100; x++)
{
Print("Loop number: " + x);
TimeDelay(delay);
}
}
i'd like to run the second instance without waiting until the first instance is finished.
function main()
{
myLoop(2);
myLoop(2);
}
so once the first myLoop started, i'd like the second myLoop to start immediately, they would be both running at the same time, my question is, what do you call this process?
is this process possible?(in java for example).
Thank you very much! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这通常需要某种形式的多线程。
您可以执行以下操作:
有关 Java 中如何工作的详细信息,请参阅并发教程< /a>.
This typically requires some form of multithreading.
You would do something like:
For details on how this works in Java, see the Concurrency Tutorial.
您的程序的 Java 实现将与此类似。
Java implementation of your program will be similar to this.
您的问题的答案。
这叫什么?
A:线程——同时运行多个任务。 (我们在 PHP/Linux 应用程序中将其称为分叉。)
这在 Java 中可能吗?
答:当然这是可能的。坦率地说,这在 Java 中更容易实现。请遵循上述答案。
The answer for your questions.
What is this called?
A: Threading - running multiple tasks at a same time. (We call it as forking in PHP/Linux applications.)
Is this possible in Java?
A: Offcourse this is possible. To be frank this is more easier to implement in Java. Please follow the above answers.
这称为异步计算。您可以使用 Futures 干净地解决这个问题。 (您实际上并不需要进行全面的多线程处理)
http://download.oracle.com/javase/6/docs/api/java/util/concurrent/Future.html
This is called an asynchronous computation. You can solve this cleanly with Futures. (You don't really need to do full-blown multithreading)
http://download.oracle.com/javase/6/docs/api/java/util/concurrent/Future.html