简体   繁体   中英

Java Producer Consumer 1 - N threads

I want to have a producer thread that would fetch from a web server new jobs. These should be stored at a local storage as queue or in memory . Then there should be a consumer thread that would read from queue and send these data over rs232 serial. Only one consumer per serial interface as it doesnt make sense otherwise. The problem is how can consumer thread be notified while it is communicating with rs232 ?

Look at the concurrent package.

http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/package-summary.html

One of the collections in there will most likely meet your needs.

The consumer threads just pull data off the queue as they are ready to process it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM