futuretask

Is it a good way to use java.util.concurrent.FutureTask ?

First of all, I must say that I am quite new to the API java.util.concurrent, so maybe what I am doing is completely wrong. What do I want to do? I have a Java application that basically runs 2 separate processing (called myFirstProcess, mySecondProcess), but these processing must be run at the same time. So, I tried to do that: publ...

Can you use Future/Futuretask objects with Spring TaskExecutors?

Is it possible to use Java FutureTask with a Spring TaskExecutor to get a Future object? I'm looking for a TaskExecutor that implements the Java ExecutorService interface, in particular the submit() method. Looking through the Spring Javadocs doesn't reveal any classes like this. Is there some alternate method to handle futures through...

Seeking Clarity on Java ScheduledExecutorService and FutureTask

I'm just starting to look into Futures and the ScheduledExecutorService in Java, and I'm wondering why my Callable isn't running on the schedule I've indicated. In this sample code, the callable runs once, but the app never completes, nor does the task run again, which is what I expected to happen (I'm sure the problem is with my expecta...

Java 5: java.util.concurrent.FutureTask - Semantics of cancel() and done()

I am currently hunting a nasty bug in a multi-threaded environment using FutureTasks and Executors. The basic idea is this to have a fixed number of threads execute individual FutureTasks that compute a result that is to be displayed in a a table (never mind the GUI aspect here). I have been looking at this for so long, I am beginning ...

How do I get FutureTask to return after TimeoutException?

In the code below, I'm catching a TimeoutException after 100 seconds as intended. At this point I would expect the code to exit from main and the program to terminate but it keeps printing to the console. How do I get the task to stop executing after timeout? private static final ExecutorService THREAD_POOL = Executors.newCachedThreadP...

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); ...

ScheduledExecutorService.scheduleAtFixedRate And Setting initialDelay To Date In The Past

I'm working on a scheduling system in Java that sends out reminders based on a startDate, endDate and occurrence (hourly, daily, weekly, monthly, Mondays, etc). Originally I was using Timer and TimerTask classes to schedule the reminders: Timer timer = new Timer(); timer.scheduleAtFixedRate(reminder, firstDate, period); I recently swi...

How to implement PriorityBlockingQueue with ThreadPoolExecutor and custom tasks

I've searched a lot but could not find a solutuion to my problem. I have my own class, BaseTask, that uses a ThreadPoolExecutor to handle tasks. If I don't want prioritization (i.e. using a LinkedBlockingQueue) this works just fine, but when I try to use a PriorityBlockingQueue I get ClassCastException because the ThreadPoolExecutor w...

How to catch exceptions in FutureTask

After finding that FutureTask running in a Executors.newCachedThreadPool() on Java 1.6 (and from Eclipse) swallows exceptions in the Runnable.run() method, I've tried to come up with a way to catch these without adding throw/catch to all my Runnable implementations. The API suggests that overriding FutureTask.setException() should help ...

a funny thing happens... ExecutorCompletionService

I have an application written in java that needs to find all the reachable hosts on the network. I use inetAddress.isReachable to do this with a timeout of 2000 milliseconds. i look up the current local machines ipaddress and based on that i attempt to reach the other ip addresses that end 1 - 255 missing out the local machines ip addr...