Does one thread invokes other thread ..
I have a problem, there is mtd A() in a class which purpose is arrange strings. As there are 5 thread invoking that mtd A(), thread one arranges that string in ascending order, thread 3 in desending order, again thread 5 in ascending order and so on...
Now my question is once the thread 1 arranges in string in ascending order after finshing work, thread 1 should call thread 3 for desending order after it finshing the work, this thread should call thread 5 and so on...
Thank in advance...
Hoping it this solution
See BlockingQueues or Lock/Condition
There are different ways to do this, but essentially your problem is "signalling" to another thread. Depending on exact requirements:
(1) You can use the Lock/Condition classes. Create a ReentrantLock, then from that call newCondition() to create Conditions that represent the "things needing to be done" on your string. Then have Thread 1 continually awaiting the condition to "sort", Thread 2 continually awaiting the condition to "reverse" etc. Each one, when it has performed the apporpriate operation, calls signal() on the lock representing the next thing that needs doing.
(2) Have a BlockingQueue that you post "commands" to saying what next needs doing with the string. Have a bunch of threads sitting in a loop waiting for commands from that queue, each time executing the command, then posting the next command to the queue. You could potentially even use a ThreadPoolExecutor, that will create the queue and threads for you. Also consider using a SynchronousQueue, which is a type of BlockingQueue that actually doesn't queue -- it effectively just "passes" the command to another thread, meaning Thread X blocks while waiting for Thread Y (or some other waiting thread) to pull the command off the queue.