• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread question

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob, I changed the name.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic