[cvs] / jsr166 / etc / notes / tim-executor-examples.html Repository:
ViewVC logotype

Diff of /jsr166/etc/notes/tim-executor-examples.html

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Mon Jan 20 18:21:43 2003 UTC revision 1.2, Mon Jan 20 18:49:23 2003 UTC
# Line 129  Line 129 
129  underlying <code>NativeImpl</code>. </p>  underlying <code>NativeImpl</code>. </p>
130    
131  <pre>  <pre>
132      class SingleThreadAdapter implements InvocationHandler {      class SingleThreadAdapter {
133    
134          public SingleThreadAdapter (String library) {          public SingleThreadAdapter (String library) {
135              this.executor = Executors.newSingleThreadExecutor();              this.executor = Executors.newSingleThreadExecutor();
# Line 184  Line 184 
184              public Object invoke (Object proxy,              public Object invoke (Object proxy,
185                                    final Method method,                                    final Method method,
186                                    final Object[] args) throws Throwable {                                    final Object[] args) throws Throwable {
187                    try {
188                  Callable task = new Callable () {                  Callable task = new Callable () {
189                      public Object call () throws Exception {                      public Object call () throws Exception {
190                          method.invoke(instance, args);                              try {
191                                    return method.invoke(instance, args);
192                                }
193                                catch (Exception e) {
194                                    throw e;
195                                }
196                                catch (Throwable e) {
197                                    throw RuntimeException(e);
198                                }
199                      }                      }
200                  };                  };
                 try {  
201                      FutureTask ftask = new FutureTask(task)                      FutureTask ftask = new FutureTask(task)
202                      executor.execute(ftask);                      executor.execute(ftask);
203                      return ftask.get();                      return ftask.get();
# Line 219  Line 227 
227          NativeInterface ni = (NativeInterface)          NativeInterface ni = (NativeInterface)
228              adapter.newInstance(new Callable<NativeInterface> () {              adapter.newInstance(new Callable<NativeInterface> () {
229                  public NativeInterface call () {                  public NativeInterface call () {
230                      return new NativeImpl();                      return new NativeImpl(); // may use native calls
231                  }                  }
232              });              });
233          int i = ni.nativeIntMethod();          int i = ni.nativeIntMethod();

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8