469,332 Members | 7,001 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

Java Thread return data

m6s
55
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.         }
  8.  
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 6252
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
m6s
55
Se efharisto.. Mallon kanei tin douleia tou...alla prepei na to dokimaso vevea...
Jan 12 '09 #3
r035198x
13,262 8TB
You are not allowed to use languages other than English in this forum.
Jan 12 '09 #4
m6s
55
OK, thank you...Probably does the work but I should try first..though
Jan 12 '09 #5
Tassos Souris
152 100+
@r035198x
You don't promote internationalization here :-)
Jan 12 '09 #6
JosAH
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,

Jos
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 zhoujie | last post: by
1 post views Thread by haryvincent176 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.