Atitit. Asynchronous Programming java. net php python js the comparison
1.1, asynchronous task , asynchronous mode, APM mode , EAP mode , TAP 1
1.1. APM mode: beginxxx/endxxx, IAsyncResult2
1.2. EAP Mode (event-based asynchronous mode)2
1.3. TAP(Task-based Asynchronous mode)2
2. Asynchronous implementation mechanism:: Mainly through the thread and thread pool implementation of ... 2
3. Development of Asynchronous Programming :: currently all through the API , in the future should be able to use the annotation method 2
4. implementation of the AEF framework : 2
5. Generic Asynchronous Programming API with specific module asynchronous API 3
6. Java Universal Asynchronous Programming API executorservice. Submit () 3
6.1. Asynchronous APIs for Java- specific modules , such as NiO 3
7.. NET ::begin/end Mode (Invoke or BeginInvoke,,) 3
7.1.1. Isynchronizeinvoke.begininvoke Method (System.ComponentModel) 4
7.2. NET also has a specific module asynchronous API WebClient 5
7.3. c#5.0 introduced two keyword async,await to provide a more concise asynchronous method invocation pattern. 5
7.4. the thread pool is so convenient, how do we use the thread pool? There are several ways to do this:6
7.4.1. Direct invocation through the class method ThreadPool.QueueUserWorkItem . 6
7.4.2. TPL introduced through the . NET Framework 4.0 (Task Parallel Library ) Task Parallel Library. 6
7.4.3. Called by an asynchronous delegate (Begininvoke/endinvoke). 6
7.4.4. Through BackgroundWorker, BackgroundWorker is A control under WinForm, WPF, It is mainly used to provide Collaborative cancellation, progress reporting, etc. under UI controls. 6
8. PHP asynchronous execution common way fscokopen () function 6
9. Python API 6
Javascript, Ajax +timer 6
. NET-to-Java asynchronous processing comparison 7
12. Reference 7
1.1, asynchronous Tasks, asynchronous mode, APMModeEapMode, TAP
An asynchronous task consists of a series of event handlers (EventHandler) and Event ( events ) , communication between eventhandlers is achieved through Event . Each EventHandler occupies one thread .
What needs asynchronous mode? The so-called pattern, in fact, is a method, as mentioned in the previous blog, is from the engineering practice summed up to solve similar or specific problems of a customary means. Common asynchronous patterns include the following:
Author :: Old Wow's paw attilax ayron, email:[email protected]
Reprint please indicate source: Http://blog.csdn.net/attilax
1.1. APMmode:beginxxx/endxxx, IAsyncResult1.2. EAPMode (event-based Asynchronous Pattern)
Windows Form
Methodnameasync
Event
1.3. TAP(Task-based asynchronous mode)
Methodnameasync
Task/task<result>
2. Asynchronous implementation mechanism:: Mainly through the thread andthread pool implementation of the...3. Development of Asynchronous programming::It's now all throughAPIof the,you should be able to use annotations in the future
Currently supported annotations are only sevlet3 ... java async-supported
4. AEFimplementation of the framework..
Realize the idea : not a java.net API all use up ... realize the Blue ...
and implement your own Api::::core.exeasyn (closue c)
In the middle , all can line up their favorite API style ...
5. Universal Asynchronous ProgrammingAPIasynchronous with a specific moduleAPI
Common API Comparison code more ...
A specific API simplifies ... .
6. JavaUniversal Asynchronous ProgrammingAPIExecutorservice. Submit ()
Executors . Newsinglethreadexecutor (). Submit (new callable
Executorservice inherits from executor, which is designed to manage thread objects for us, simplifying concurrent programming, Executor allows us to manage the lifecycle of threads without showing, and is the preferred way to start tasks after JDK 5.
6.1. Javaasynchronous for a specific moduleAPI,For exampleNiO
7.. net::Begin/end mode (Invoke or BeginInvoke,,)
(There are four ways to do this, please refer to the blog in front of Debuglzq:.) NET Asynchronous Programming summary----Four implementation modes ).
7.0.1. Isynchronizeinvoke.begininvokeMethod(System.ComponentModel)
Control.Invoke Method (Delegate) : executes on the thread that owns the underlying window handle of this control the specified delegate.
Control.BeginInvoke Method (Delegate): on thread that creates the control's underlying handle Asynchronous Execution specifies the delegate.
Either the Invoke or BeginInvoke method requires a delegate object as a parameter. The delegate is similar to the address of the callback function, so the caller can then marshal the function address that needs to be called to the interface thread. In these methods, if you include code that changes the state of the control, it is the interface thread that eventually executes the method, which avoids the competitive conditions and avoids unforeseen problems. If other threads directly manipulate the control that the interface thread belongs to, then there will be a race condition, causing unpredictable results.
by invoking or BeginInvoke , the difference between the two is that one causes the worker to wait, while the other does not.
Using invoke to complete marshaling of a delegate method is similar to using the SendMessage method to send a message to the interface thread, which is a synchronous method. This means that the Invoke method does not return until the method of the invoke Marshal is executed, and the caller thread is blocked.
Marshaling a delegate method using the BeginInvoke method, similar to communicating using PostMessage, is an asynchronous method. That is, the method returns immediately after marshaling, does not wait for the execution of the delegate method to end, and the caller thread will not be blocked. But callers can also use the EndInvoke method or other similar WaitHandle mechanisms to wait for the completion of an asynchronous operation.
But in the internal implementation, both invoke and BeginInvoke use the PostMessage method, which avoids the problem of SendMessage. The synchronous blocking of the Invoke method is done by the WaitHandle mechanism.
, that is, the asynchronous call on the control class BeginInvoke does not open a new thread to complete the delegate task, but instead lets the interface control's owning thread complete the delegated task. It seems that asynchronous operations are not necessarily accurate in opening new threads.
7.1. NetThere are also specific modules that are asynchronousAPIWebClient
WebClient as a high-level package for WebRequest. NET has helped us to encapsulate this asynchronous pattern.
client. DownloadStringAsync (new URI);
7.2. c#5.0Two keywords introducedAsync,awaitto provide a more concise asynchronous method invocation pattern.
PrivateAsyncvoidButton1_Click (Objectsender, EventArgs e) { intLength =awaitShowuricontentasyncawait ("Http://www.cnblogs.com/DebugLZQ"); TextBox1.Text=length. ToString (); } //AsyncTask<int> showuricontentasyncawait (stringURI) { using(WebClientClient =New WebClient()) { stringText =client. Downloadstring (URI); returntext. Length; } }
7.3.the thread pool is so convenient, how do we use the thread pool? There are several ways to do this:7.3.1. By class methodThreadPool.QueueUserWorkItemcalled directly. 7.3.2. By. NET Framework 4.0introduced byTPL(Task Parallel Library) Task Parallel Library.
The main two classes in the TPL are Task and Parallel. The new C + + standard also introduces similar concepts parallel_for, Parallel_foreach, parallel_invoke and so on.
For more information, see the link below.
7.3.3. Through an asynchronous delegate (Begininvoke/endinvoke) call.
7.3.4. ByBackgroundWorker, BackgroundWorkeris aWinForm,WPFunder a control that is primarilyUsed to provideUICollaborative cancellation under controls, progress reporting, and more. 8. PHPcommon ways to execute asynchronouslyFscokopen () function 9. Python api10. Javascript, Ajax +timer
Comparison of asynchronous processing between. NET and Java
Korean Java is better, the name is better ....
12. Reference
The use of Invoke and BeginInvoke (reprinted)_odeo_ Sina blog . htm
Paip.c#.net problems with multithreaded call controls -attilax column - Blog channel -CSDN.NET.htm
Paip. C#.net multithreaded Access ToolStripStatusLabel-. NET Tutorial _.net programming _.net Developing technical Articles - Red and Black Alliance . htm
Thinking about asynchronous Programming in Java. -martin.chen- Blog Park . htm
NET Asynchronous Programming summary ---- Four modes of implementation -debuglzq- Blog Park . htm
Starting with c#5.0 : Summarizing The history of C # asynchronous invocation methods -debuglzq- Blog Park . htm
PHP Asynchronous execution common Way-bravezhe column-Blog channel-CSDN.NET.htmpython network programming----non-blocking or asynchronous Programming-bj2008_0201-chinaunix blog. htm
Asynchronous programming under C # and its synchronization mechanism-Salomon-blog Park. htm
Paip.java multithreading parameters and return values the use of the future futuretask. -Attilax's Column-Blog channel-CSDN.NET.htm
Servlet3.0 new features, Servlet3 new features, Servlet3 annotations, Servlet3 asynchronous processing "Sweet potato yiu"-Sweet potato-iteye technology website. htm
Atitit. Asynchronous programming java. NET PHP python js comparison