Threading issue

Hi everyone~

Want to ask, if i got a method to send something to the network using SocketChannel’s write(), will it be safe if multiple threads are calling the method and pushing stuff?
What’s the best way to do something like this? Keeping a vector and insert the stuff to send to it??

Just wanna ask if it is wise to synchronize my sendMessage() method which calls the SocketChannel.write() or if it’ll be better to keep a queue?

Am I asking the wrong question here?.. ???

[quote]Am I asking the wrong question here?.. ???
[/quote]
Partly, yes. Your question is too vague and lacks important details - which is fine, except that it means it’s more work for people to answer, hence probably fewer people are willing to have a go. For instance, you make no mention of the SC’s mode (blocking or not). You also don’t say precisely which method you’re using.

However, more to the point, it looks like you didn’t bother to read the API documentation. Maybe I’m misunderstanding your question, but it looks like you should just read the method comment for write( ByteBuffer ) [hint: look at the 5th paragraph]. IF that doesn’t answer your question, then perhaps it will give you an idea of what you are asking that is differnt, and you can come back and ask a more detailed question that people can help with.

Turned out that my NIO concept’s a bit wrong before(still a beginner now though…). Please forgive me for asking the stupid question :-/ (I admit I didn’t read throughly the docs before=.=)
I’ve that sorted out now, thx blahblahblahh

IF you’re new to nio, you might want to try the incomplete NIO tutorials on JGF (see link below, and go to the articles section) - there’s enough there to get going quite far.

I read that tutorial a few weeks ago. I really liked it.

[quote]I read that tutorial a few weeks ago. I really liked it.
[/quote]
Great. You might want to also vote here: http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=Networking;action=display;num=1081097137;start=0
since I haven’t signed the book contract yet, and the more responses that gets the happier it makes the publishers ;).

Done :slight_smile:
good luck