| Author |
Thread question
|
Gene Kaplun
Greenhorn
Joined: Apr 03, 2002
Posts: 2
|
|
Hi, I am new to Java. Can someone help me with my problem, please? This is a barcode scanning process. I have a class that extends Thread. There are few if statements in the run() method. When scanner reads the command the code goes to the appropriate 'if' statements and process the command. My problem is that while one of the command is running the scanner freezes up until the code is finished. This is a single thread class now. I need to separate each command in the separate threads. How I can do it? Thanks,
|
 |
Rob Ross
Bartender
Joined: Jan 07, 2002
Posts: 2205
|
|
First, you should change your name before a bartender asks you to. This site has a naming policy that basically want you to use two names, seperated by a space, preferably your real name. As to your problem, look at using a producer/consumer pattern. You'll have two threads that will share a common data structure. One thread just reads from the scanner and posts each new event to this data structure, and a second thread periodically polls the data structure for new events, and acts on any it finds, then removes them from the data structure after it has finished processing. [ April 03, 2002: Message edited by: Rob Ross ]
|
Rob
SCJP 1.4
|
 |
Gene Kaplun
Greenhorn
Joined: Apr 03, 2002
Posts: 2
|
|
|
Thanks Rob, I changed the name.
|
 |
 |
|
|
subject: Thread question
|
|
|