futures

What are futures?

What are futures? It's something to do with lazy evaluation. ...

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

Integrating MVC Futures in Spark view engine without killing intellisense

I want to add MVC futures to my project and make the assembly available in my spark views however it's not accepting it whatsoever. I can use Microsoft.Web.Mvc fine from my classes (controllers/models etc) but they're just not showing up in .spark files. I cannot use <use assembly""/> since that kills my intellisense. And if i try to a...

Java Thread - weird Thread.interrupted() and future.cancel(true) behaviour

Hi all, I want to manage a list of Futures objects returned by my TaskExecutor. I've something like this List<Future<String>> list void process(ProcessThis processThis) { for ( ...) { Future<String> future = taskExecutor.submit(processThis); list.add(future) } } void removeFutures() { for(Future fu...

CompletionService.take().isDone() always true?

Is it safe to assume that java.util.concurrent.CompletionService.take().isDone() will always return true? If so, why does take() return a Future, rather than the value directly? If not, what does "completed task" as used in the documentation mean? ...

Understanding future/threading

I am trying useing futures for the first time. It seems smart that you can cancel a job but it is not working as expected. In the example below only the first job is cancelled. The rest are completed. Have I missunderstood the use of futures? public class ThreadExample { public static void main(String[] args) throws InterruptedExce...

Problem with futures in c++0x .

Hi, I have written a small program , to understand how futures work in c++0x. while running the code I get an error like " error: 'printEn' was not declared in this scope". I am unable to understand what the problem is..Kindly point out what I am doing wrong here and if possible write the correct code for the same.. #include <future> #i...

re: adding more threads to forkjoinpool

Word up y'all I recently successfully experimented with Scala futures, got future { my shiznit } all over da place. I'm pleased as punch w/ the gains I'm seeing from the parallelism and whatnot, but I'm only seeing 4 worker threads. Wanna see some more. I've been looking all over for how I can crank up the number of threads to 11, but n...

controlling the order of submitted futures

In this example, i am submitting a few files to my comparator object. It all works fine, except that i noticed that order in which files are submitted is not always teh same order in which they are returned. Any suggestions on how i can better control this? ExecutorService pool = Executors.newFixedThreadPool(5); CompletionService<Pro...

What happens when a Scala "Future" is garbage collected?

Say I have a Stream that's rather expensive to compute. I can easily create a thread that "computes ahead" just by writing something like import scala.actors.Futures._ val s = future { stream.size } If I then throw away the reference to this Future, will that thread be killed off by the garbage collector? ...

Use case for Future.cancel(false)?

In what situation would one want to pass false for the mayInterruptIfRunning parameter to Future.cancel()? If I understand correctly, if you pass false and the task is cancelled but the thread is not interrupted, the result (or ExecutionException) will never be accessible because the task is still marked as cancelled (i.e. isCancelled()...

Expose current progress of an @Asynchronous function to use in View

In my JEE6-App (running on Glassfish 3.0.1) I have an EmailEJB which has to send lots of mails. The mails are sent asynchronously, so its annotated with the new EJB3.1 @Asynchronous, letting it be run in a separate Thread. Now i want the user to be informed about the current status of the method: How many mails have already been sent? S...

program hangs when using multiple futures with multiple remote actors

I start two remote actors on one host which just echo whatever is sent to them. I then create another actor which sends some number of messages (using !! ) to both actors and keep a List of Future objects holding the replies from these actors. Then I loop over this List fetching the result of each Future. The problem is that most of the ...

Scala actor to non-actor interaction (or synchronizing messages from an actor to a servlet)

I have the following scala code: package dummy import javax.servlet.http.{HttpServlet, HttpServletRequest => HSReq, HttpServletResponse => HSResp} import scala.actors.Actor class DummyServlet extends HttpServlet { RNG.start override def doGet(req: HSReq, resp: HSResp) = { def message = <HTML><HEAD><TITLE>Rando...

Why aren't my scala futures more efficient ?

I'm running this scala code on a 32-bit quad-core Core2 system: def job(i:Int,s:Int):Long = { val r=(i to 500000000 by s).map(_.toLong).foldLeft(0L)(_+_) println("Job "+i+" done") r } import scala.actors.Future import scala.actors.Futures._ val JOBS=4 val jobs=(0 until JOBS).toList.map(i=>future {job(i,JOBS)}) println("Running....

Consuming the results produced by an ExecutorService. Which class?

I wish I would have written the class/interface name down but I didn't... When looking through the JDK javadocs I saw reference to a class/interface with the purpose of collecting and consuming the results produced by an ExecutorService (completed Futures<T>s), possibly elsewhere in the system. At the time I took a mental note of it be...

React for futures

I am trying to use a divide-and-conquer (aka fork/join) approach for a number crunching problem. Here is the code: import scala.actors.Futures.future private def compute( input: Input ):Result = { if( pairs.size < SIZE_LIMIT ) { computeSequential() } else { val (input1,input2) = input.split val f1 = future( compute(inpu...