Purging Java tasks
In some circumstances, it can be desirable to terminate tasks running in Java™ without bringing down the whole JVM. Although it is not
guaranteed that using SET TASK PURGE
terminates the Java workload, it can be effective in some situations. Take caution when using
SET TASK PURGE
on tasks running Java. You
should have an understanding of the running workload to avoid potentially disruptive
effects.
About this task
Prior to CICS® TS 5.4, TASK PURGE
of
individual tasks was not allowed if the task was running Java.
Purging of Java tasks is now enabled, but you should be aware
that the Java programming language and JVM are not designed to
allow threads to be stopped without co-operative interrupt processing. CICS employs stronger measures to forcibly terminate a thread and if effective
terminates the Java program with an error. In particular the
Thread.stop()
method is used to inject a ThreadDeath
error
directly into the application. As a result the Java stack is
immediately unwound and locks are released ahead of normal application flow. This action has the
potential to leave shared Java objects and data in an
inconsistent state. You should carefully assess the impact on any applications still running.
In an ideal scenario, all Java code would be designed to respect interrupts. In practice, it is hard to achieve, especially when third-party components are used. The following information gives a useful understanding why terminating threads in the JVM is difficult to achieve, and what patterns a Java programmer should follow to make their application interruptible: Java Thread Primitive Deprecation.
Procedure
SET TASK
PURGE
command is issued, then the parent JVMSERVER is identified. The Java thread on which the task is running is located, and a
Thread.stop()
is issued against the thread. If successful a
ThreadDeath
error is returned and the Java
thread is terminated.
PURGE
protected requires FORCEPURGE
to be
issued.TASK KILL
command might be ineffective. The only way to stop a Java task in a tight non-yielding loop, is to escalate to a JVMSERVER
DISABLE KILL
.