Forums Register Login

Thread question

+Pie Number of slices to send: Send
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,
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
Thanks Rob, I changed the name.
I brought this back from the farm where they grow the tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 696 times.
Similar Threads
get IP, but not 127.0.0.1
Bluetooth open problem : Connector.open() blocking..
first JavaRanch question
Need Help for an Array.
spawning a process
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 05:21:27.