Make java multithreaded until input is entered

I am trying to create simple code to simulate parallel connection in a DB2 database using java. my current code looks something like this:

class TheThread implements Runnable{
@override
public void run(){
    //make the database connection
    //need to pause here until any button pressed
    //execute query to the database
}
}

      

the program will do several hundred to thousands of threads at the same time, so I want to make sure all threads are connected before the request is made so that it is actually being processed at the same time

How can i do this?

+3


source to share


1 answer


You can use CyclicBarrier from java.util.concurrent package



static CyclicBarrier b = new CyclicBarrier(nConnections);

public void run() {
    // make the database connection
    b.await();  //threads will stop here untill nConnections are opened
    ...

      

+1


source







All Articles