最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ajax - Multi-threading in javascript - Stack Overflow

programmeradmin4浏览0评论

Is there any way to implement a multi-threading execution in Javascript. I am implementing a pagination in my application, with a target of the minimum waiting time for the user. Neither I want all the data to be brought to the client-side in one go, nor do I want to make a server as well as a DB hit on every "next/previous" button clicked. So I want the browser to create a request and update my data list, while the front end user has not reached the last page.

If there is anyone who has implemented this, then please suggest me.

Is there any way to implement a multi-threading execution in Javascript. I am implementing a pagination in my application, with a target of the minimum waiting time for the user. Neither I want all the data to be brought to the client-side in one go, nor do I want to make a server as well as a DB hit on every "next/previous" button clicked. So I want the browser to create a request and update my data list, while the front end user has not reached the last page.

If there is anyone who has implemented this, then please suggest me.

Share Improve this question edited Jul 30, 2012 at 20:42 Rustam 1,9332 gold badges16 silver badges35 bronze badges asked May 6, 2012 at 6:54 Sashi KantSashi Kant 13.5k9 gold badges49 silver badges71 bronze badges 1
  • here the timing of the backend call will by dynamic, depending on the total (request-response time)/number of pages – Sashi Kant Commented May 6, 2012 at 7:02
Add a ment  | 

4 Answers 4

Reset to default 3

You can use setInterval of and setTimeOut function to gain multi-threaded effect but it is not true multi-threading you can read nice discussion here

You might consider looking at the infinite scrolling technique. There are a number of plugins out there that facilitate this, including Paul Irish's Infinite Scroll.

This is the same technique used by sites like Twitter so that the page updates as the user scrolls down, creating a seamless UI experience for the user and eliminating delays.

You can use timers (setTimeout) to simulate asynchronocity in JS. Timed events run when

  • The timer is reached
  • and when JS is not doing anything

So using setTimeout to create "gaps" in execution allow other "code in waiting" to be executed. It's still single threaded, but it's like "cutting the line"

Here's a sample

It is very easy to do it by using the Concurrent.Thread JavaScript library, which is free and open source towards this end. No SetInterval or SetTimeout required.

You can download it from here: http://sourceforge/apps/mediawiki/jsthread/index.php?title=Main_Page

Tutorial explaining the use of the library can be found here: http://www.infoq./articles/js_multithread

发布评论

评论列表(0)

  1. 暂无评论