executors

Does this need explicit synchronization?

I have two threads, and I want to make sure I am doing the synchronization correctly on the LinkedBlockingQueue.. Is this correct? Or is the explicit synchronization on (messageToCommsQueue) not necessary? Declaration: private LinkedBlockingQueue<BaseMessage> messagesToCommsQueue; Method one: private void startOperationModeSta...

how do FutureTasks and CachedThreadPool work

Hi, I currently have code that does the following: private final static ExecutorService pool = Executors.newCachedThreadPool(); public void foo(){ FutureTask<MyObject> first_task = createFutureTask(); FutureTask<MyObject> second_task = createFutureTask(); ... pool.execute(first_task); pool.execute(second_task); ...

Help with java threads or executors: Executing several MySQL selects, inserts and updates simmultaneously

Hi. I'm writing an application to analyse a MySQL database, and I need to execute several DMLs simmultaneously; for example: // In ResultSet rsA: Select * from A; rsA.beforeFirst(); while (rsA.next()) { id = rsA.getInt("id"); // Retrieve data from table B: Select * from B where B.Id=" + id; // Crunch some numbers using the dat...

java thread reusage via executor

Hi, I am confused on the following: To use threads in a Java program, the simplest way is to extend Thread class and implement the runnable interface (or simply implement runnable). To start the thread's execution. we must call the Thread's method start(), which in turn calls method run() of the thread. And so the thread starts. The met...

Executors run longer than timeout value

Here is a code segment of scala. I set timeout as 100 mills. Out of 10000 loops, 106 of them run more than 100 mills without throwing exceptions. The largest one is even 135 mills. Any reason why this is happening? for (j <- 0 to 10000) { total += 1 val executor = Executors.newSingleThreadExecutor val result = executor.submit[Int...