English 中文(简体)
我在 Java100条深线的时间里怎么办10条read?
原标题:How do I run 10 threads at a time from 100 threads in Java?

using6

附录一创造100条线,每个线上完成一项任务。 我想不断走10条路。 这意味着,如果我正在接近1-10,而且已经读完8篇,我就希望能够在11条之后开始,而不必等待1-10条加入。

How can I do this?

这方面的一个途径可能是使用Alive(Alive()方法,但我很想知道,我是否能够在没有投票的情况下这样做。

Thanks.

最佳回答

为什么需要这样做?

更好的办法是建立10座read,并向它提交100项任务。 这将产生完全相同的效果——100项任务中有10项同时执行。

ExecutorService pool = Executors.newFixedThreadPool(10);

for (int i = 0; i < 100; i++)
    pool.submit(...);
问题回答

使用Executorservice,配对10thread to submitting mandate。 您总结的任何工作都将在奎埃完成,10个read子将从那里完成1,000个工作。

When you say "at a time" while talking about concurrency is Confusing. If you use a ExecuterService with thread pool size of 10, 10 out of 100 threads will be enabled for execution. But remember if you have only 1 CPU and one of your thread has higher priority, all other threads may stay in waiting state. My suggestion is to tune your number threads based on the number of CPU available.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签