Hi, I am beginning to make an outline of my networking approach. I have a question about threads. When a new client in networked mode launches the application and a new thread is spawned, what should be in the run method? Thanks! [ December 13, 2004: Message edited by: Daniel Simpson ]
I am not sure that I understand your question, so if I am going off on a tangent, please ignore my ramblings and if you can spot where I have misunderstood you then please correct me.
If you are talking about using the SwingUtilities.invokeLater() to explicitly start a new thread to do the booking, then you probably want your runnable method to contain all the method calls needed to do a booking. You might want some to use some sort of Observable pattern to get information back to the main thread about success / failure of the booking process.
If you are talking about using Sockets to connect to the server, then there are plenty of tutorials showing how to do this. The simplest way to do this is to spawn a new thread as soon as you have a connection, then the runnable method will open your streams and start sending and receiving data on them.
We should not be talking about RMI, since RMI creates it's own threads.
Thanks for your reply, Andrew. In my implementation of the book method, it goes, lock-->verify data-->update(book)-->unlock. I guess my question is, if I call the book method from the run method, how do I pass the parameter of the record number into the run method?
I'm fairly new to networking/multithreading so I am sorry for all the confusion. Forgive me if I am wrong, but in the code, wouldn't there need to be a thread creation using Runnable parameter from your inner class and also calling the start() method on that thread?? Also, the run method I was referring to was . Thanks!
Hi Daniel, From what I have read, I don’t think you are handling client requests within thread pool, if not I think you should consider it, it is not a necessity but handling requests in a thread pool is always better.
Any way, as for how to handle requests at server side, you can set accepted socket client in the constructor of your handling thread (that is if you are not using thread pool).
Your code in very simple way could look like:
Now inside your run method you will read request Object and handle it there.
Best Regards <br /> <br />Omar F. Kalaldah<br />---------------------<br />SCJP, SCJD, SCBCD
posted 15 years ago
That makes sense! Thanks Omar!
SCJP 1.4<br />SCJD 1.4
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps