[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

jcsp Parallel doesn't handle Error cleanly



Hi Peter,

My colleague Chris has made a suggestion for a small change to the Parallel.java class in JCSP 1.0 rc5.  There exists a catch for Exceptions that ensures that problems are immediately drawn attention to (around line 530).

try {
    process.run ();
} catch (Exception e) {
    synchronized (System.out) {
        System.out.println (
        "\n*** jcsp.lang.Parallel - a process threw the following exception:"
        );
        e.printStackTrace();
    }
}


However, this does not handle Error conditions, rare though they might be.  A non-daemon thread can cause a hang.

Would it be better do you think to change the catch to deal with Throwable like this:

try {
    process.run ();
} catch (Throwable e) {
    synchronized (System.out) {
        System.err.println (
        "\n*** jcsp.lang.Parallel - a process threw the following exception:"
        );
        e.printStackTrace();
        System.exit(-1);
    }
}

There is also a call to System.exit here, included because such conditions are not really recoverable.  However, some people might consider this to be going too far.  What do you think?

My other comment is more general and concerns the System.out messages.  In normal industry practice as you no doubt know, production code doesn't ever do System.out for diagnostic information.  Rather a logging API is used (my own preference is Log4j).  However, the Parallel class uses System.out for error messages.  These should perhaps be changed; a simple approach might be simply to use System.err instead of introducing an external dependency.  Do you agree?

The affected classes are Parallel, ParThread, ProcessManager, ProcessNetwork.  Of these, ProcessManager and ProcessNetwork also use System.out for diagnostic information which is not really satisfactory for being used in  production code.

Regards,
Rick
-- 
Richard Beton BSc (Hons)
Consultant
Email: richard.beton@xxxxxxxxxx
Telephone: +44 (0)1794 833458

Roke Manor Research Ltd, A SIEMENS Company.
Old Salisbury Lane, Romsey, Hampshire S051 0ZN

http://www.roke.co.uk/

--

Visit our website at www.roke.co.uk

Roke Manor Research Ltd, Roke Manor, Romsey, Hampshire SO51 0ZN, UK.

The information contained in this e-mail and any attachments is proprietary to
Roke Manor Research Ltd and must not be passed to any third party without
permission. This communication is for information only and shall not create or
change any contractual relationship.