• 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

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: 23951
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
 
You may have just won ten million dollars! Or, maybe a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic