multithreading - Java - RunnableFuture and SortProcessor -


i'm studying code here method, 'm not quite sure does:

1) there runnablefuture, why assigned futuretask, why not futuretask = new futuretask?

2) meant new sortprocessor<e>, java or class.

public synchronized void sort() {     if (this.internalstate == internalstate.read) throw new illegalstateexception();      final runnablefuture<e> leftfuture = new futuretask<e>(new sortprocessor<e>(this.leftchild));     final runnablefuture<e> rightfuture = new futuretask<e>(new sortprocessor<e>(this.rightchild));      new thread(leftfuture, "left-child").start();     new thread(rightfuture, "right-child").start();      try {         this.leftcache = leftfuture.get();         this.rightcache = rightfuture.get();     } catch (final interruptedexception interrupt) {         throw new threaddeath();     } catch (final executionexception exception) {         final throwable cause = exception.getcause();         if (cause instanceof error) throw (error) cause;         if (cause instanceof runtimeexception) throw (runtimeexception) cause;         throw new assertionerror();     }      if (this.leftcache != null | this.rightcache != null) {         this.internalstate = internalstate.read;     } } 

runnablefuture interface , futuretask concrete impl of interface. it's practice declare variables abstract type greater flexibility.

sortprocessor must someones custom class implements callable interface in order used in constructor futuretask.

it looks 2 threads kicking off asynchronous tasks sorting type of tree


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -