• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread question  RSS feed

 
Gene Kaplun
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Gene Kaplun
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob, I changed the name.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!