471,887 Members | 1,150 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

Java Thread return data

Expand|Select|Wrap|Line Numbers
  1. MovAvg run = new MovAvg(_symbol, this, SumDays.SMALL );
  2. threadExecutor.execute(run);
  3. Collection<Double> vl = run.getMovAvg().values();
  4.         Iterator itr = vl.iterator();
  5.         while(itr.hasNext()){
  6.             System.out.println(itr.next());
  7.         }
This snippet generates, or at least tries to generate a Moving Average. The MovAvg is a Runnable class. I send in the symbol, the values ( a class of inherited treemap values) and the period of days ).
In order to take back the results I try the to build a Collection and then generate an iterateion on the values of this collection.

First: I have a Null exception, which I believe it has to do with the fact, that the thread might not have started yet? If so, how can I handle that the next step will be executed right after the execution of the thread ? Well what I don't see is how to "plug-in" wait, notify thing...

Second: Is it right the way I am trying to collect the values? If I have secured that the thread will run before we reach to this point...

Thank you...
Jan 11 '09 #1
6 6365
Tassos Souris
152 100+
Have a look at the java.util.concurrent.Callable interface.
It is similar to Runnable (in the sense that they can be executed by another thread), with the exception that Callable can return a result and throw a checked exception.
Also, have a look at the Future interface that provides you with methods to check if the computations are complete, to wait, and to retrieve the result of the computation specified by a Callable.

Take a look at the Java concurrent package API. There are some examples there.
Jan 11 '09 #2
Se efharisto.. Mallon kanei tin douleia tou...alla prepei na to dokimaso vevea...
Jan 12 '09 #3
13,262 8TB
You are not allowed to use languages other than English in this forum.
Jan 12 '09 #4
OK, thank you...Probably does the work but I should try first..though
Jan 12 '09 #5
Tassos Souris
152 100+
You don't promote internationalization here :-)
Jan 12 '09 #6
11,448 Expert 8TB
@Tassos Souris
It's just a practicality; if the majority of the people online would've spoken Dutch, we'd all be speaking Dutch here ;-) English is the "Lingua Franca" of the net.

kind regards,

Jan 12 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Ravi Tallury | last post: by
4 posts views Thread by Robert Schneider | last post: by
6 posts views Thread by Rhino | last post: by
2 posts views Thread by ironpingwin | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.