aspose file tools*
The moose likes Features new in Java 7 and the fly likes Async IO threading model Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "Async IO threading model" Watch "Async IO threading model" New topic
Author

Async IO threading model

marwen Bakkar
Ranch Hand

Joined: Jan 28, 2010
Posts: 84
Hi,

I just figured there's the new Async stuff.
If I call a write operation and get back a future. It means that the calling thread is free to proceed. That leaves the question in what thread does the writing happen?
Similarly, where do completion handlers run?
Where can I read more about this?

Thanks.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
marwen Bakkar wrote:Hi,

I just figured there's the new Async stuff.
If I call a write operation and get back a future. It means that the calling thread is free to proceed. That leaves the question in what thread does the writing happen?


That depends on how the "write operation" you call is implemented. Can you be more specific? What concurrency classes and methods are you using?

A common scenario involving a Future would be if you're using an ExecutorService and called submit(). The question would be, what sort of ExecutorService is this, and how was it configured? Often it might have been created by a call to Executors.newFixedThreadPool(). In that case, tasks will run on one of the threads in the thread pool. Other implementations of ExecutorService might do other things.

marwen Bakkar wrote:Similarly, where do completion handlers run?

Similarly, depends on the the implementation of the completion handler. Often there's a thread pool involved.

quote=marwen BakkarWhere can I read more about this?
The main options are:

1. The Java API
2. Various free online articles about the java.util.concurrent packages released in JDK 5 and later. (Try googling "java ExecutorService", for example)
3. A book such as Java Concurrency in Practice

I recommend the last of these in particular, but all the info you need is present in free online sources, if you read them carefully enough.
marwen Bakkar
Ranch Hand

Joined: Jan 28, 2010
Posts: 84
Well since this is Java 7 forum I thought it'd be clear I'm referring to NIO2 channels, such as AsynchronousSocketChannel. Sorry for the confusion.

I found this in the package description :

Asynchronous channels are bound to an asynchronous channel group for the purpose of resource sharing. A group has an associated ExecutorService to which tasks are submitted to handle I/O events and dispatch to completion handlers that consume the result of asynchronous operations performed on channels in the group. The group can optionally be specified when creating the channel or the channel can be bound to a default group. Sophisticated users may wish to create their own asynchronous channel groups or configure the ExecutorService that will be used for the default group.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
OK, interesting.

It looks like you start with something like

And which threads run the tasks is determined by the implementation of ExecutorService that you pass in, which is typically some sort of thread pool.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Async IO threading model