Re: Splitting processor performance for multiple processes in Java
- From: Mark Space <markspace@xxxxxxxxxxxxx>
- Date: Sun, 30 Nov 2008 12:09:22 -0800
Lew wrote:
Mark Space wrote:class MyTask implements Callable<MyResult> {
public MyResult call() throws Exception {
MyResult result = null;
// do stuff, then:
return result;
}
}
A nit: initializing a local variable to 'null' is not always optimal, though it is sometimes necessary.
Since I did compile this example, I just did that to get rid of the compiler warning. I used a local variable because, for someone unfamiliar with Callable, I thought declaring a local variable, then on the next line putting the "do stuff" comment, and then finally returning the local was less confusing than say:
class MyTask implements Callable<MyResult> {
public MyResult call() throws Exception {
// do stuff, then:
return new MyResult();
}
}
Which is cleaner but perhaps less clear how the result should be derived.
Another nit: "throws Exception" got added by the auto-code generation. In this example it's of course not needed.
.
- References:
- Prev by Date: Re: concept of session in J2EE
- Next by Date: Re: concept of session in J2EE
- Previous by thread: Re: Splitting processor performance for multiple processes in Java
- Next by thread: concept of session in J2EE
- Index(es):
Relevant Pages
|