JavaScript Web Worker<br />by Sun<br />2011.6.10<br />
假死<br />单线程<br />大数据量计算<br />
setTimeout?<br />setInterval?<br />
Web Worker<br />"多线程"时代<br />
Work NOW -- 主线程<br />// 将要后台运行的一段代码<br />varworker = new Worker("worker.js");<br />// 如何处理后台worker返回的结果<br />worker.onmess...
Work NOW -- 子线程<br />/**<br /> * 得到主线程传过的消息, 启动线程进行大数据计算.<br /> * mainThread.postMessage -> workerThread.onmessage<br /> *...
本地XHR?<br />子线程<br />worker.js<br />onmessage<br />postMessage(data)<br />主线程<br />mainThread.js<br />onmessage<br />postM...
NO DOM<br />
Browser Support<br /><ul><li>Firefox 3.5(1.9.1)
Opera 10.60
Chrome 3
Safari 4</li></ul>Where is Internet Explorer ?<br />
Upcoming SlideShare
Loading in …5
×

iShare 技术 Web Worker_20110610_Sun

770 views

Published on

Web Worker开启JavaScript多线程时代

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
770
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

iShare 技术 Web Worker_20110610_Sun

  1. 1. JavaScript Web Worker<br />by Sun<br />2011.6.10<br />
  2. 2. 假死<br />单线程<br />大数据量计算<br />
  3. 3. setTimeout?<br />setInterval?<br />
  4. 4. Web Worker<br />"多线程"时代<br />
  5. 5. Work NOW -- 主线程<br />// 将要后台运行的一段代码<br />varworker = new Worker("worker.js");<br />// 如何处理后台worker返回的结果<br />worker.onmessage = function (event) {<br />console.log(event.data);<br />}<br />
  6. 6. Work NOW -- 子线程<br />/**<br /> * 得到主线程传过的消息, 启动线程进行大数据计算.<br /> * mainThread.postMessage -> workerThread.onmessage<br /> */<br />onmessage = function (event) {<br />// 从event.data中取得主线程传来的数据<br />varmainThreadData = event.data;<br />// 将结果传递给主线程<br /> // workerThread.postMessage -> mainThread.onmessage<br />postMessage(mainThreadData);<br />};<br />
  7. 7. 本地XHR?<br />子线程<br />worker.js<br />onmessage<br />postMessage(data)<br />主线程<br />mainThread.js<br />onmessage<br />postMessage(data)<br />子线程1<br />worker1.js<br />子线程2<br />worker2.js<br />
  8. 8. NO DOM<br />
  9. 9. Browser Support<br /><ul><li>Firefox 3.5(1.9.1)
  10. 10. Opera 10.60
  11. 11. Chrome 3
  12. 12. Safari 4</li></ul>Where is Internet Explorer ?<br />
  13. 13. Q&A<br />
  14. 14. 参考<br />JavaScript Threading With HTML5 Web Workers<br />
  15. 15. 谢谢!<br />

×