01: /**************************************************************************************
02: * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package examples.async;
08:
09: import is.Async;
10: import is.Service;
11:
12: @Service
13: public class Math {
14:
15: static {
16: System.out.println("Math.'static initializer'");
17: }
18:
19: @Async(timeout=10)
20: public void add(int a, int b) {
21: System.out.printf("[ %s ] %d + %d = %d\n", Thread
22: .currentThread().getName(), new Integer(a),
23: new Integer(b), new Integer(a + b));
24: }
25:
26: @Async(timeout=2)
27: public void subtract(int a, int b) {
28: System.out.printf("[ %s ] %d - %d = %d\n", Thread
29: .currentThread().getName(), new Integer(a),
30: new Integer(b), new Integer(a - b));
31: }
32:
33: public static void main(String args[]) throws Throwable {
34: Math math = new Math();
35: System.out
36: .println("\n================ Async sample =================");
37:
38: math.add(5, 4);
39: math.add(1, 5);
40: math.add(2, 6);
41: math.add(4, 4);
42: math.add(8, 4);
43: math.subtract(7, 4);
44: math.subtract(3, 5);
45: math.subtract(1, 6);
46: math.subtract(4, 4);
47: math.subtract(8, 4);
48: Thread.sleep(100);
49: System.exit(0);
50: }
51: }
|