开发者

Java - Help solving application problem

I have a c开发者_Python百科lass that creates objects from another class, reading the necessary data from a file. Basically, it's a thread that loads the data and adds to a queue. The data it loads is a String and an Integer per time. The problem is that the app will have 2 of those classes, so 2 threads reading from one file and addin on a queue. I'm having a lot of problems with it, so how would be the best method I could do in order to make the 2 classes add objects in the queue?

Thanks!


BlockingQueue

ConcurrentLinkedQueue


the best way will be to use semaphores...... consider using semaphores

here is a link of and example on how to use it....

hope it helps....


I think what you are referring to is the typical producer-consumer problem.

Producer/Consumer threads using a Queue should help.


You're having a synchronization issue. Do you truly need two threads? If so, put the code that adds to the queue into a synchronized block.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜