• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Buffering using Thread Synchronization

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am having a little trouble with my buffer that uses Thread synchronization. What is meant to happen is that the InputManager inputs a String into the buffer. The buffer is then passed to LineToChar, where it takes the String from the buffer using the take() method and extracts the string into individual letters. These individual letters should then be passed to the OutputManager through another buffer, where the OutputManager outputs the individual letters onto the screen.

The problem is that it appears to be getting stuck in deadlock after the letter "e". Can you please offer suggestions on why it is doing this and point me in the right direction on how to solve this? My code is below:








Hope you can help me.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see the code for LineToChar. Can you show that please?
 
John Turner
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I forgot about that! I was tired when posting last night. Here is LineToChar.java

 
author
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You never start the Output Manager threads. In LineToChar for each input line you create a new OutputManager on the same bufferOut but never start it. So nothing consumes the lines from bufferOut. Creating a thread object doesn't start the thread. And you probably only need to call and start one OutputManager object, not create them every time.

Also, I think there an error in InputManager: to start a thread, use the method start(), do not call directly run(). Run() is just a method like any other, and if you call it directly, it will be executed in your existing thread. Start() on the other hand creates a new thread and then executes the run() method there. So the only special thing about run() is the name, in that start() knows about it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic