On 22/06/2022 9:03 am, Charles Mills wrote:
Can one write a Started Task in Java? What would the JCL look like (neglecting
application-specific items)?
This is a basic Java program that runs and responds to MODIFY and STOP
commands:
import java.time.*;
import com.ibm.jzos.MvsCommandCallback;
import com.ibm.jzos.MvsConsole;
public class JavaStc
{
static volatile boolean stopped = false;
static final Instant startTime = Instant.now();
public static void main(String[] args) throws InterruptedException
{
if (!MvsConsole.isListening())
{
MvsConsole.startMvsCommandListener();
}
MvsConsole.registerMvsCommandCallback(new CommandCallback());
while (!stopped)
{
Thread.sleep(1000);
}
}
static class CommandCallback implements MvsCommandCallback
{
public void handleModify(String arg0)
{
if (arg0.equals("REPORT"))
{
Duration runtime = Duration.between(JavaStc.startTime,
Instant.now());
System.out.println("Runtime: " + runtime.toString());
}
else
{
System.out.println(arg0 + " not recognized. Valid
commands: REPORT");
}
}
public void handleStart(String arg0)
{
// do nothing
}
public boolean handleStop()
{
JavaStc.stopped = true;
return false;
}
}
}
JCL to run it under the JZOS batch launcher (which allows you to access
JCL DDs from the Java program):
//G EXEC PGM=JVMLDM80,REGION=256M,
// PARM='/ JavaStc'
//*
//STEPLIB DD DISP=SHR,DSN=VENDOR.LINKLIBE
//*
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//STDOUT DD SYSOUT=*
//STDERR DD SYSOUT=*
//CEEDUMP DD SYSOUT=*
//ABNLIGNR DD DUMMY
//*
//STDENV DD *
export JAVA_HOME=/usr/lpp/java/J8.0
LIBPATH=/lib:/usr/lib:"${JAVA_HOME}"/bin
LIBPATH="$LIBPATH":"${JAVA_HOME}"/lib/s390
LIBPATH="$LIBPATH":"${JAVA_HOME}"/lib/s390/j9vm
LIBPATH="$LIBPATH":"${JAVA_HOME}"/bin/classic
export LIBPATH="$LIBPATH":
export CLASSPATH="/home/andrewr/java"
IJO="-Xms16m -Xmx128m"
export IBM_JAVA_OPTIONS="$IJO "
This JCL is adapted from the samples provided with JZOS.
One quirk is that the modify commands need to specify APPL=, i.e.
MODIFY JOBNAME,APPL=REPORT
The command callbacks happen on a different thread I think so you need
to consider synchronization. Other than that it is quite simple.
Andrew Rowley
--
Andrew Rowley
Black Hill Software
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN