KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > foxtrot > Job


1 /**
2  * Copyright (c) 2002-2005, Simone Bordet
3  * All rights reserved.
4  *
5  * This software is distributable under the BSD license.
6  * See the terms of the BSD license in the documentation provided with this software.
7  */

8
9 package foxtrot;
10
11 /**
12  * A time-consuming task to be executed in the Worker Thread that does not throw checked exceptions. <br />
13  * Users must implement the {@link #run} method with the time-consuming code:
14  * <pre>
15  * Job task = new Job()
16  * {
17  * public Object run()
18  * {
19  * long sum = 0;
20  * for (int i = 0; i < 1000000; ++i)
21  * {
22  * sum += i;
23  * }
24  * return new Integer(sum);
25  * }
26  * };
27  * </pre>
28  * RuntimeExceptions or Errors thrown by the <code>run()</code> method will be rethrown automatically by
29  * {@link Worker#post(Job)} or {@link ConcurrentWorker#post(Job)}.
30  * @see Worker
31  * @see ConcurrentWorker
32  * @version $Revision: 1.6 $
33  */

34 public abstract class Job extends Task
35 {
36    /**
37     * The method to implement with time-consuming code.
38     * It should NOT be synchronized or synchronize on this Job instance, otherwise the AWT Event Dispatch Thread
39     * cannot efficiently test when this Job is completed.
40     * Overridden to remove the throws clause, so that users does not
41     * have to catch unthrown exceptions.
42     */

43    public abstract Object JavaDoc run();
44 }
45
Popular Tags