Here's my problem:
I have a whole bunch of identical objects. These objects interface with a server. It takes 4 or 5 seconds to get data from the server, as the server is slow.
Now i need all the objects to get data. So i call MyObject.getData() for each object. I could do it in a series but 20 objects, each taking 5 seconds is too slow. I thought I should use threads and have each object on its own thread.
Here's my question:
If i make the objects extend thread. Will a call to o MyObject.getData(); run in that object's thread, or in the thread the method was called from? I know i can use Thread.Run() to get the object going but thats not what i want. I want to get methods running at my will.
So how do i do this?
Thanks so much.
Thread.run()will not "get the object going" -- that's a common misconception. What you'll want to invoke isThread.start().RunnableorCallable(like most of the answers suggest). Using these interfaces instead allows you to still start manualThreadobjects if you want, but easily switch to using anExecutorService.