• 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

Linking two Threads in a Client-Server Socket program - Java

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I create threads of class A and each sends a serialized object to a Server using ObjectOutputStream.

The Server creates new Threads B for each socket connection (whenever a new A client connects)

B will call a synchronized method on a Shared Resource Mutex which causes it (B) to wait() until some internal condition in the Mutex is true.

In this case how A can know that B is currently waiting?

Note:
A is a GUI. each serialized object sent over socket is added to a queue in Mutex. So, at a particular time if the queue becomes full, B will have to wait till it frees some slots in the queue. So the end user (A GUI thread) has to see a message like "Please wait while a slot becomes free" . User will have to wait for a reply from B (when it becomes notified by Mutex) in order to continue operations in the GUI (i.e: click a button to open the next JFrame and carry on work)...



How each class is dependent.

(A1 = an instance of class A)

A1--------->B1-------->| ------ |
A2--------->B2-------->| Mutex |
A3--------->B3-------->| ------ |

Hope this description is clear. Thanks in advance.
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can 'B' set a flag before going to wait and reset it after the wait is over? This way A can know if B is waiting.
reply
    Bookmark Topic Watch Topic
  • New Topic