Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I got your question right, you need non-blocking IO for files. I have bad news for you then.</p> <h2>NIO</h2> <p>Java NIO in Java6 supports only blocking operation when working with files. You may notice this from the fact <a href="http://java.sun.com/javase/6/docs/api/java/nio/channels/FileChannel.html" rel="nofollow noreferrer"><code>FileChannel</code></a> does not implement <a href="http://java.sun.com/javase/6/docs/api/java/nio/channels/SelectableChannel.html" rel="nofollow noreferrer"><code>SelectableChannel</code></a> interface. (NIO does support non-blocking mode for sockets however)</p> <p>There is NIO.2 (<a href="http://jcp.org/en/jsr/detail?id=203" rel="nofollow noreferrer">JSR-203</a>) specification aimed to overcome many current limits of java.io and NIO and to provide support for asynchronous IO on files as well. NIO.2 is to be released with Java 7 as far as I understand.</p> <p>These are Java library limits, hence you will suffer from them in Scala as well.</p> <h2>Actors</h2> <p>Actors are based on Fork-Join framework of Doug Lea (at least in branch 2.7.x till <a href="http://www.scala-lang.org/node/3533" rel="nofollow noreferrer">version 2.7.7</a>). One quote from <a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/FJTask.html" rel="nofollow noreferrer">FJTask class</a>:</p> <blockquote> <p>There is nothing actually preventing you from blocking within a FJTask, and very short waits/blocks are completely well behaved. But FJTasks are not designed to support arbitrary synchronization since there is no way to suspend and resume individual tasks once they have begun executing. FJTasks should also be finite in duration -- they should not contain infinite loops. FJTasks that might need to perform a blocking action, or hold locks for extended periods, or loop forever can instead create normal java Thread objects that will do so. FJTasks are just not designed to support these things.</p> </blockquote> <p>FJ library is enhanced in Scala to provide a unified way permitting an actor to function like a thread or like an event-based task depending on number of working threads and "library activity" (you may find explanation in technical report "<a href="http://lamp.epfl.ch/~phaller/doc/haller07coord.pdf" rel="nofollow noreferrer">Actors that unify Threads and Events</a>" by Philipp Haller and Martin Odersky).</p> <h2>Solution?</h2> <p>But after all if you run blocking code in an actor it behaves just like if it being a thread, so why not use an ordinary <code>Thread</code> for blocking reads and to send events to event-based actors from this thread?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload