Var Thread = {
RunNum: 0, // Number of threads currently running
MaxNum: 10, // The maximum number of threads simultaneously executed-1 indicates Unlimited
CommandList: new Array (),
Start: function (){
// Window. status = this. runNum;
If (this. maxNum! =-1 & this. runNum> = this. maxNum ){
Return;
}
If (this. commandList. length <= 0 ){
This. runNum = 0;
Return false;
}
This. runNum ++;
Var _ this = this;
Var tFun = function (){
If (! _ This. commandList [0]) return;
Var command = _ this. commandList [0]. shift ();
Command. apply (_ this, _ this. commandList [0]. concat (
Function () {// alert (2)
If (_ this. runNum> 0) _ this. runNum --;
SetTimeout (function () {_ this. start. apply (_ this)}, 1 );
}));
_ This. commandList. shift ();
}
SetTimeout (tFun, 1 );
SetTimeout (function () {_ this. start. apply (_ this)}, 10 );
}
}
<Script src = "prototype. js"> </script>
<Script type = "text/javascript" defer = "defer">
Function test (obj, info, callback ){
Callback = callback | new Function ();
New Ajax. Request ('test. xml', {method: 'get ',
OnSuccess: function (o ){
$ (Obj). innerHTML + = info + 'done <br> ';
Callback ('complete ');
},
OnFailure: function (o ){
$ (Obj). innerHTML + = info + 'failed <br> ';
Callback ('failed ');
},
OnComplete: function (o ){
Document. body. scrollTop = 9999;
}
});
}
Var Thread = {
RunNum: 0, // Number of threads currently running
MaxNum: 5, // The maximum number of threads simultaneously executed-1 indicates Unlimited
CommandList: new Array (),
Start: function (){
// Window. status = this. runNum;
If (this. maxNum! =-1 & this. runNum> = this. maxNum ){
Return;
}
If (this. commandList. length <= 0 ){
This. runNum = 0;
Return false;
}
This. runNum ++;
Var _ this = this;
Var tFun = function (){
If (! _ This. commandList [0]) return;
Var command = _ this. commandList [0]. shift ();
Command. apply (_ this, _ this. commandList [0]. concat (
Function () {// alert (2)
If (_ this. runNum> 0) _ this. runNum --;
SetTimeout (function () {_ this. start. apply (_ this)}, 1 );
}));
_ This. commandList. shift ();
}
SetTimeout (tFun, 1 );
SetTimeout (function () {_ this. start. apply (_ this)}, 10 );
}
}
For (var I = 0; I <100; I ++ ){
Thread. commandList. push (new Array (test, document. body, I + 1 ));
};
Thread. start ();
</Script>
<Body>
</Body>