Link Details

Link 177886 thumbnail
User 207602 avatar

By jimbojw
via trephine.org
Published: Apr 28 2009 / 02:14

The HTML 5 specification promises to bring a new level of sophistication to web applications by introducing worker threads. Some browsers already support them. Unfortunately, it will mostly likely be many years before HTML 5 is widely supported (greater than say 75% market share). The good news is that you can have JavaScript worker threads today in all major browsers by using trephine. This article shows you how.
  • 7
  • 3
  • 3676
  • 5

Comments

Add your comment
User 310113 avatar

b.m replied ago:

0 votes Vote down Vote up Reply

I've voted it down, since while it's cool to have JavaScript threads in HTML5, the article by no means describes JavaScript thread creation - as the title and description suggests - but rather how to integrate it with Trephine, and use regular Java threads.

User 207602 avatar

Jim Wilson replied ago:

0 votes Vote down Vote up Reply

Thanks for taking the time to comment - I appreciate the explanation of your down vote, an uncommon gesture on the web. :)

It wasn't my intention to mislead anyone, which is why I put the line "you can have JavaScript worker threads today in all major browsers by using trephine" in the summary. I felt, and still feel, that this accurately reflects the topic of the article.

You're correct that the underlying engine powering the threads is indeed Java. This is an implementation detail. The code to define and launch the threads is all JavaScript.

The examples in the article use Java idioms such as grabbing a reference to java.lang.Thread.currentThread() as a way to emulate doing expensive work, whereas a real app would presumably do something much more substantial. In an effort to clarify the intended use, I have written a followup article providing (hopefully more relevant) pure JavaScript examples. I hope this helps to clear things up, thanks for reading!

http://www.dzone.com/links/alternative_javascript_worker_thread_api.html

User 310113 avatar

b.m replied ago:

0 votes Vote down Vote up Reply

Jim, my biggest problem with the title and description, it's that you actually need to have Java installed in order to run "JavaScript threads" - so it's no JavaScript thread really. This bottom line is that threads run inside the JVM, and not inside the browser.

You might argue that since the applet it's inside the browser it's not the case. I beg to differ. I think to some extent the same approach would be doable using Flash (even if I doubt they have a JavaScript parser inside).

This is why you need to use Rhino inside trephine, and not the javascript parser from the browser.

Anyway, you've did an excellent work on trephine. Do you have any plans to release it opensource?

User 207602 avatar

Jim Wilson replied ago:

0 votes Vote down Vote up Reply

Hi b.m,

All good points. AFAIK, Flash doesn't support multi-threading in-and-of itself, but one could achieve similar results by having a separate SWF for each "thread", and in principle the OS should run these independent of eachother. Also, Flash does not have a built-in ActionScript or JavaScript interpreter, a fact which I've always felt was rather limiting. Maybe someone will use Alchemy to compile V8 or SquirrelFish into an AS3 library - that could work out very well, hmmm...

Anyway, as to the open sourcing question: although it's free to use by hotlinking, and the source is available for academic review, I do not have any immediate plans to release the trephine core code under an OSS license. Auxiliary code, such as demos and code snippets in blog articles, are released under an MIT-style permissive license or directly into the Public Domain as indicated. Hope this helps!

User 207602 avatar

Jim Wilson replied ago:

0 votes Vote down Vote up Reply

Hello again,

Since our last chat here, I have decided to release all the code for trephine under the MIT License. If you'd like to try it out[1], I appreciate all feedback[2], thanks!

[1] http://github.com/jimbojw/trephine
[2] wilson.jim.r@gmail.com

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (7)



Voters Against This Link (3)



Spring Integration
Written by: Soby Chacko
Featured Refcardz: Top Refcardz:
  1. Search Patterns
  2. Python
  3. C++
  4. Design Patterns
  5. OO JS
  1. PhoneGap
  2. Spring Integration
  3. Regex
  4. Git
  5. Java