I need to execute a queue of thread. I need that only one thread is in execution and then put other thread in a queue and when the current thread is completed I need to pass to the first in the queue.
I need that to implement live search on my JTable. The table holds 50.000 rows so without this method the performance are really bad. I' ve no idea how to implement it. Anyone can help me? Thanks!
Use a single-threaded Executor from Executors.newSingleThreadExecutor(). You can pass your jobs as Runnable objects to the Executor and let it do the work for you.
private final Executor executor = Executors.newSingleThreadExecutor();
public void doSomethingWith(final Object obj) {
executor.execute(new Runnable() {
public void run() {
// Do something with obj
}
});
}
Put the code you want to run once-at-a-time in the run method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With