Asynchronous Method Invocation in Join Java and Polyphonic C
Total Page:16
File Type:pdf, Size:1020Kb
Kamalakshi N. et al / International Journal of Computer Science and Information Technology (IJCSIT) 2010, Vol1 (1), 1-7 Asynchronous method invocation in Join java and polyphonic c# Kamalakshi N Dr.H.Naganna Asst Professor, Professor & Head Dept of Computer Science &Engg Dept of Information Science Saptagiri College of Engineering, &Engg SJB Institute of Bangalore INDIA Technology,Bangalore INDIA [email protected] [email protected] Abstract: In most programming pattern described in 1996 by Allan languages a called method is executed Vermeulen.[2][3]. The event-based synchronously, i.e. in the thread of asynchronous pattern in .NET execution from which it is invoked. If Framework and the the method needs a long time to java.util.concurrent.FutureTask class in completion, e.g. because it is loading Java use events to solve the same data over the internet, the calling problem. This pattern is a variant of thread is blocked until the method has AMI whose implementation carries more finished. When this is not desired, it is overhead, but it is useful for objects possible to start a "worker thread" and representing software components. invoke the method from there. In most programming environments this One common use of AMI is in the active requires many lines of code, especially object design pattern. Alternatives are if care is taken to avoid the overhead synchronous method invocation and that may be caused by creating many future objects[4].An example for an threads. AMI solves this problem in application that may make use of AMI is that it augments a potentially long- a web browser that needs to display a running ("synchronous") object web page even before all images are method with an "asynchronous" loaded. variant that returns immediately, along with additional methods that make it The following are possible reasons for easy to receive notification of defining a method as asynchronous: completion, or to wait for completion at a later time. This paper focuses on The function within the method asynchronous method invocation in two uses the update task - The popular languages Join java and C# . method is terminated by an event generated when the update task is 1 .Introduction successful. If you nevertheless define the method as a In (multithreaded) object-oriented synchronous method under these programming, asynchronous method circumstances, the workflow data invocation (AMI), also known as may be inconsistent with the asynchronous method calls or current data in the database due asynchronous pattern is a design pattern to update terminations or delays. for asynchronous invocation of potentially long-running methods of an The method can also be called object.[1] It is equivalent to the IOU outside the workflow - If it is 1 Kamalakshi N. et al / International Journal of Computer Science and Information Technology (IJCSIT) 2010, Vol1 (1), 1-7 possible that a user may call the Asynchronous methods function encapsulated in the Order class modifiers for method outside the workflow determining the order that although the object is also being patterns are matched processed under the control of a workflow at the same time, you Concurrency in most popular should implement the method as programming languages is implemented an asynchronous method. It is using constructs such as semaphores and therefore irrelevant whether monitors. Libraries are emerging (such calling the function takes place as the Java concurrency library JSR-166) inside or outside the workflow that provide higher-level concurrency system. The workflow continues semantics. Communicating Sequential after the event occurs. Processes (CSP), Calculus of Communicating Systems (CCS) and Pi An asynchronous method with have higher-level synchronization comprehensive functionality is behaviours defined implicitly through called in the task - This task gets the composition of events at the its specific character from the interfaces of concurrent processes. Join terminating events. e.g., In a task, calculus, in contrast, has explicit a specific order is to be released synchronization based on a localized for billing. In the task, call the conjunction of events defined as (general) method Process order reduction rules. Join semantics try to and enter the event Billing block provide explicit expressions of deleted as the terminating event. synchronization without breaching the object-oriented idea of modularization, It is also to be possible for the task to be including dynamic creation and terminated by events not necessarily destruction of processes and channels. from method processing - The task in which the method Process sales order is The Join Java language can express executed is also terminated by the event virtually all published concurrency Customer unable to pay patterns without explicit recourse to low- level monitor calls. In general, Join Java 2Join Java programs are more concise than their Java equivalents. The overhead Join Java is a programming language introduced in Join Java by the higher- that extends the standard Java level expressions derived from the Join programming language with the join calculus is manageable. The semantics of the join-calculus. It was synchronization expressions associated written at the University of South with monitors (wait and notify) which Australia within the Reconfigurable are normally located in the body of Computing Lab by Dr. Von Itzstein. methods can be replaced by Join Java expressions (the Join methods) which The Join Java extension introduces three form part of the method signature. new language constructs: Join methods 2 Kamalakshi N. et al / International Journal of Computer Science and Information Technology (IJCSIT) 2010, Vol1 (1), 1-7 Join methods Example: A Join method is defined by two or more class ordered SimpleJoinPattern Join fragments. A Join method will { void A() & B() { execute once all the fragments of the } Join pattern have been called. If the void A() & C() { return type is a standard Java type then } the leading fragment will block the caller void A() & D() { } until the Join pattern is complete and the signal D() & E() { method has executed. If the return type } is of type signal then the leading } fragment will return immediately. All trailing fragments are asynchronous so Asynchronous methods will not block the caller. Asynchronous methods are defined by Example: using the signal return type. This has the same characteristics as the void type class JoinExample { except that the method will return int fragment1() & immediately. When an asynchronous fragment2(int x) { //will return value of x method is called a new thread is created //to caller of fragment1 to execute the body of the method. return x; } Example: } class ThreadExample { Ordering modifiers signal thread(SomeObject x) { //this code will execute Join fragments can be repeated in in a new thread } multiple Join patterns so there can be a } case when multiple Join patterns are completed when a fragment is called. Such a case could occur in the example C Sharp is a multi-paradigm below if B(), C() and D() then A() are programming language that supports called. The final A() fragment completes imperative, generic and object-oriented three of the patterns so there are three programming. It is a part of the possible methods that may be called. Microsoft .NET Framework. It is similar The ordered class modifier is used here to C++ in its object-oriented syntax and to determine which Join method will be is also influenced by Java and Delphi. called. The default and when using the Polyphonic C# extends C#. MC# is an unordered class modifier is to pick one extension of Polyphonic C# that can of the methods at random. With the work on the .NET platform. C-omega is ordered modifier the methods are an extension to C# that succeeded prioritised according to the order they Polyphonic C#. It enables access to data are declared. stores and includes constructs that support concurrent programming. 3 Kamalakshi N. et al / International Journal of Computer Science and Information Technology (IJCSIT) 2010, Vol1 (1), 1-7 3.Polyphonic C# public string Get() & public async Put(string s) { Polyphonic C# adds just two new return s; concepts: asynchronous methods and } chords. } The code above defines a class Buffer Asynchronous Methods. Conventional with two instance methods, which are methods are synchronous, in the sense jointly defined in a single chord. Method that the caller makes no progress until string Get() is a synchronous method the callee completes. In Polyphonic C], taking no arguments and returning a if a method is declared asynchronous string. Method async Put(string s) is then any call to it is guaranteed to asynchronous (so returns no result) and complete essentially immediately. takes a string argument. Asynchronous methods never return a If buff is a instance of Buffer and one result (or throw an exception); they are calls the synchronous method buff .Get() declared by using the async keyword then there are two possibilities: instead of void. Calling an asynchronous —If there has previously been an method is much like sending a message, unmatched call to buff .Put(s) (for some or posting an event.Since asynchronous string s) then there is now a match, so methods have to return immediately, the the pending Put(s) is dequeued and the behaviour of a method such as async body of the chord runs, returning s to the postEvent(EventInfo data) f // large caller of buff .Get(). method body g is the only thing it could —If there are no previous unmatched reasonably be: the call returns calls to buff .Put(.) then the call to buff immediately and ‘large method body’ is .Get() blocks until another thread scheduled for execution in a different supplies a matching Put(.). thread (either a new one spawned to Conversely, on a call to the service this call, or a worker from some asynchronous method buff .Put(s), the pool).