title: To use the Gears WorkerPool in GWT do I have to write the same code in Java and Javascript?
body: <p>In order to use the WorkerPool (Javascript Threads) class and functionality in GWT/Gears, do I need to write my code in both Java and Javascript?  Upon inspection of <a href="http://code.google.com/docreader/#p=gwt-google-apis&amp;s=gwt-google-apis&amp;t=GearsGettingStartedWorkerPool" rel="nofollow noreferrer">WorkerPool - Getting Started</a> and the sample WorkerPool application in the GWT-Gears-1.1 download package it seems that I need to.  It seems that the Java code is used to demonstrate the synchronous nature of Javascript and the same algorithm in Javascript is used for the asynchronous calls.  </p>
  
  <p>Am I missing something?  Wasn't GWT created so that you don't have to write Javascript code?  Why can't you write your WorkerThread code in Java and have the compiler compile it to Javascript?</p>
  
  <p>Here is the relevant Java code from that url:</p>
  
  <pre><code> public void syncWorker(String message) {
  // Busy wait for 5 seconds
  long end = System.currentTimeMillis() + 5000;
  while (true) {
    int busyCounter = 1000;
    String busyVar;
    while (busyCounter-- &gt; 0) {
      busyVar = "garbage" + busyCounter;
    }
    long now = System.currentTimeMillis();
    if (now &gt; end) {
      break;
    }
  }
  logMessage("Approved: " + message);
  }
  </code></pre>
  
  <p>Here is the relevant Javascript code in worker.js (notice how it is the same algorithm written in Javascript):</p>
  
  <pre><code>function doWork(message) {
  // Busy wait for 5 seconds
  var start = new Date();
  while (true) {
    var busyCounter = 10000;
    var busyVar;
    while (busyCounter-- &gt; 0) {
      busyVar = "garbage" + busyCounter;
    }
    var now = new Date();
    if (now.getTime() - start.getTime() &gt; 5000) {
      break;
    }
   }
  
   return "Approved: " + message;
   };
  </code></pre>
  
  <p>Here is the call in Java:</p>
  
  <pre><code>wp = Factory.getInstance().createWorkerPool();
  wp.setMessageHandler(GearsWorkerPoolTutorial.this);
  workerId = wp.createWorkerFromUrl("worker.js");
  </code></pre>
  
  <p>Can anyone with experience in GWT and Gears shed some light on this?</p>
  
  <p>Thanks!</p>
  
  <p>Edit:</p>
  
  <p>It seems according to this <a href="http://markmail.org/message/gxipzth2jheccpha#query:+page:1+mid:sabv4llpymbavt7t+state:results" rel="nofollow noreferrer">http://markmail.org/message/gxipzth2jheccpha#query:+page:1+mid:sabv4llpymbavt7t+state:results</a> my suspicions are true.  I'm not sure I understand why this limitation exists.  I would love to read any insight on the matter.</p>
  
  <p>Edit 2:</p>
  
  <p>This also seems to confirm it: <a href="http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/658f6665e5b09bed" rel="nofollow noreferrer">http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/658f6665e5b09bed</a></p>