从java中的线程池运行静态方法
使用线程池在多个线程中运行静态方法的最佳方法是什么? 我还尝试将参数传递给静态方法。类似于
Class A{
public static runTask(int i){
....
}
}
和 来自主要内容:
ThreadPool pool = new ThreadPool(5, "poolname");
for(int i=1; i<10; i++){
A.runTask(i) // but on a new thread...
}
谢谢!
What is the best way to run a static method in several threads, using a thread pool?
Also I trying to pass an argument to the static method. something like
Class A{
public static runTask(int i){
....
}
}
and from a main:
ThreadPool pool = new ThreadPool(5, "poolname");
for(int i=1; i<10; i++){
A.runTask(i) // but on a new thread...
}
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 java.util.concurrent.Executors。它应该满足您的需求。这是一个使用它的简单示例:
Have a look at the documentation for java.util.concurrent.Executors. It should meet your needs. Here is a simple example of using it:
详细实施指南请参见:
http://java.sun.com/developer/Books/javaprogramming/threads /chap13.pdf
Please find the detailed implementation guides:
http://java.sun.com/developer/Books/javaprogramming/threads/chap13.pdf