• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Multi Thread Interaction

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,
Following is the code i am facing problem to understand. Here we are making 2 threads from the 'main' thread , which contains Input Stream & Output Stream of the Socket respectively.


Now when i run both files (ie. server side & client side) & try to send data from server to client through console , following is the output of the server

Question1. On the 7th line of the output , when the 'Server Input Thread' stops executing & the 'main' thread comes in 'Waiting for Client to connect...' gets printed by the main thread, then why doesnt the next line ' Client connected. IP: /192.168.1.15' got printed. Is it because at that perticular time 'Server Input Thread' started executing ?
Question2. When i sent 'Hello Client'...Everything goes fine but when i enter 'Tarun' , then why doesnt the following gets print before printing 3 ?
"2 Current Thread is : Server Output Thread
AFTER TAKING INPUT FROM CONSOLE "

Thanks In Advance!!!
 
author
Posts: 23899
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tarun Oohri wrote:
Question1. On the 7th line of the output , when the 'Server Input Thread' stops executing & the 'main' thread comes in 'Waiting for Client to connect...' gets printed by the main thread, then why doesnt the next line ' Client connected. IP: /192.168.1.15' got printed. Is it because at that perticular time 'Server Input Thread' started executing ?



The main thread and the input thread are two different threads (actually, more depending on the number of clients). The main thread goes back to accepting another connection after starting the input thread. The ordering in how the two threads perform their tasks is dependent on the scheduler -- and without synchronization, you can't assume an order.

Henry
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic