Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Web Workers - Few Questions

 
Ranch Hand
Posts: 343
Mac OS X Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand that Web Workers allow running JavaScript in parallel on a web page, without blocking the user interface. I also understand that Web Workers don't have access to the DOM that means I cannot select any html element. Also, Web Workers do not have access to 'parent'.

I have two questions related to Web Workers:-

1. When will I normally use a Web Worker?
2. As per the Web Workers specification given by WHATWG,

workers are expected to be long-lived, have a high start-up performance cost, and a high per-instance memory cost.


Why will I want to use something like this on client-side and that too in parallel to another JavaScript?

I tried to understand the examples given in the specification but couldn't understand their value.
 
author
Posts: 25
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Palak,

As for the first question: "When will I normally use a Web Worker?"
I gave some ideas in previous thread here on coderanch.
As for more 'real world example' please checkout: http://greenido.wordpress.com/2012/05/20/web-workers-and-big-data-a-real-world-example/

As for the 2nd question - Please think on web workers as a solution to do:
* Network to/from the server in the background
* Create one central component that manage your local storage.
This case is interesting because it can even be done with shared workers and give you ability to have one point of 'true' to all the instances of your web app (e.g. many windows, tabs that share the same 'thread').
* WebGL - you wish to run some complex matrix manipulation
and many many more :)

 
reply
    Bookmark Topic Watch Topic
  • New Topic