Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Is DatagramSocket thread safe?

Reply
Thread Tools

Is DatagramSocket thread safe?

 
 
ponce
Guest
Posts: n/a
 
      02-26-2006
Hi all

Does anyone know whether Java's DatagramSocket is thread safe?
I am currently writing a multithreaded program that accesses the same
DatagramSocket, and these threads are reading and writing simultanously
from and to this same socket instance.

Thanks!
 
Reply With Quote
 
 
 
 
IchBin
Guest
Posts: n/a
 
      02-26-2006
ponce wrote:
> Hi all
>
> Does anyone know whether Java's DatagramSocket is thread safe?
> I am currently writing a multithreaded program that accesses the same
> DatagramSocket, and these threads are reading and writing simultanously
> from and to this same socket instance.
>
> Thanks!


DatagramSocket is thread-safe.



--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
Reply With Quote
 
 
 
 
christian.bongiorno@gmail.com
Guest
Posts: n/a
 
      02-26-2006
DataGramSocket is an abstraction of a type of socket. Thread-safety is
dependent upon collisions of reads/writes resulting in an
non-determinable state of your application.

However the two together are not intrinsically a problem because of the
way the socket is accessed -- .getInputStream() getOutputStream()

writing to the outputstream has no thread implied impact on reading the
inputstream from the Java viewpoint (the protocol you are working with
might have something to say differently). More importantly would be how
the OuputStream for the socket handles writing from multiple threads.

As per Above, the socket is thread-safe

Christian
http://christian.bongiorno.org/

 
Reply With Quote
 
EJP
Guest
Posts: n/a
 
      02-27-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> DataGramSocket is an abstraction of a type of socket. Thread-safety is
> dependent upon collisions of reads/writes resulting in an
> non-determinable state of your application.
>
> However the two together are not intrinsically a problem because of the
> way the socket is accessed -- .getInputStream() getOutputStream()


Bzzt, DatagramSockets don't have streams. However:

(i) DatagramSocket reads and writes are independent of each other.
(ii) DatagramSocket writes are atomic so they are thread-safe.
(iii) DatagramSocket reads are synchronized by Java and they are also
atomic at the OS level so again they are thread-safe.
 
Reply With Quote
 
ponce
Guest
Posts: n/a
 
      02-27-2006
Thank you so much for everyone's help!

How do you all actually find all these information? I tried googling
for it yesterday, but couldn't find any relevant info...

EJP wrote:
> (E-Mail Removed) wrote:
>
>> DataGramSocket is an abstraction of a type of socket. Thread-safety is
>> dependent upon collisions of reads/writes resulting in an
>> non-determinable state of your application.
>>
>> However the two together are not intrinsically a problem because of the
>> way the socket is accessed -- .getInputStream() getOutputStream()

>
>
> Bzzt, DatagramSockets don't have streams. However:
>
> (i) DatagramSocket reads and writes are independent of each other.
> (ii) DatagramSocket writes are atomic so they are thread-safe.
> (iii) DatagramSocket reads are synchronized by Java and they are also
> atomic at the OS level so again they are thread-safe.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DatagramSocket.receive waits forever (despite 3 second SoTimeout)! Imran Java 1 10-15-2005 12:19 AM
receive selectively from a DatagramSocket Lorenzo Bettini Java 4 02-16-2005 08:01 AM
java DatagramSocket gets same port on linux neutrondba@hotmail.com Java 1 01-18-2005 04:39 AM
datagramsocket ipv6 & BindException Josh Java 0 01-11-2005 07:58 PM
Multi-threaded access to a DatagramSocket Danny Woods Java 7 10-14-2003 09:08 AM



Advertisments