ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahx_5.4.0.1/rzahxcollservusertranexjava.htm

289 lines
11 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Java example: Integrating user-defined transactions into Collection Services" />
<meta name="abstract" content="This Java example program shows how to use the Start transaction and End transaction APIs to integrate user-defined transaction performance data into Collection Services." />
<meta name="description" content="This Java example program shows how to use the Start transaction and End transaction APIs to integrate user-defined transaction performance data into Collection Services." />
<meta name="DC.Relation" scheme="URI" content="rzahxcollservusertran.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rzahxcollservusertranexjava" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Java example: Integrating user-defined transactions
into Collection Services</title>
</head>
<body id="rzahxcollservusertranexjava"><a name="rzahxcollservusertranexjava"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Java example: Integrating user-defined transactions
into Collection Services</h1>
<div><p>This Java™ example program shows how to use the Start transaction
and End transaction APIs to integrate user-defined transaction performance
data into Collection Services.</p>
<div class="section"><div class="note"><span class="notetitle">Note:</span> By using the code examples, you agree to the terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div>
<pre>import com.ibm.iseries.collectionservices.PerformanceDataReporter;
// parameters:
// number of TXs per thread
// number of threads
// log|nolog
// enable|disable
// transaction seconds
public class TestTXApi
{
static TestTXApiThread[] thread;
static private String[] TxTypeString;
static private byte[][] TxTypeArray;
static private String TxEventString;
static private byte[] TxEventArray;
static
{
int i;
// initialize transaction type strings and byte arrays
TxTypeString = new String[20];
TxTypeString[ 0] = "Transaction type 00";
TxTypeString[ 1] = "Transaction type 01";
TxTypeString[ 2] = "Transaction type 02";
TxTypeString[ 3] = "Transaction type 03";
TxTypeString[ 4] = "Transaction type 04";
TxTypeString[ 5] = "Transaction type 05";
TxTypeString[ 6] = "Transaction type 06";
TxTypeString[ 7] = "Transaction type 07";
TxTypeString[ 8] = "Transaction type 08";
TxTypeString[ 9] = "Transaction type 09";
TxTypeString[10] = "Transaction type 10";
TxTypeString[11] = "Transaction type 11";
TxTypeString[12] = "Transaction type 12";
TxTypeString[13] = "Transaction type 13";
TxTypeString[14] = "Transaction type 14";
TxTypeString[15] = "Transaction type 15";
TxTypeString[16] = "Transaction type 16";
TxTypeString[17] = "Transaction type 17";
TxTypeString[18] = "Transaction type 18";
TxTypeString[19] = "Transaction type 19";
TxTypeArray = new byte[20][];
for ( i = 0; i &lt; 20; i++ )
try
{
TxTypeArray[i] = TxTypeString[i].getBytes("Cp037");
} catch(Exception e)
{
System.out.println("Exception \"" + e + "\" when converting");
}
}/* static */
public static void main( String[] args )
{
int numberOfTXPerThread;
int numberOfThreads;
boolean log;
boolean enable;
int secsToDelay;
// process parameters
if ( args.length &gt;= 5 )
try
{
numberOfTXPerThread = Integer.parseInt( args[0] );
numberOfThreads = Integer.parseInt( args[1] );
if ( args[2].equalsIgnoreCase( "log" ) )
log = true;
else
if ( args[2].equalsIgnoreCase( "nolog" ) )
log = false;
else
{
System.out.println( "Wrong value for 3rd parameter!" );
System.out.println( "\tshould be log|nolog" );
return;
}
if ( args[3].equalsIgnoreCase( "enable" ) )
enable = true;
else
if ( args[3].equalsIgnoreCase( "disable" ) )
enable = false;
else
{
System.out.println( "Wrong value for 4th parameter!" );
System.out.println( "\tshould be enable|disable" );
return;
}
secsToDelay = Integer.parseInt( args[4] );
} catch (Exception e)
{
System.out.println( "Oops! Cannot process parameters!" );
return;
}
else
{
System.out.println( "Incorrect Usage." );
System.out.println( "The correct usage is:" );
System.out.println( "java TestTXApi numberOfTXPerThread numberOfThreads
log|nolog enable|disable secsToDelay");
System.out.println("\tlog will make the program cut 1 log transaction per start / end pair");
System.out.println("\tdisable will disable performance collection to minimize overhead");
System.out.print("\nExample: \"java TestTXApi 10000 100 log enable 3\" will call " );
System.out.println("cause 10000 transactions for each of 100 threads");
System.out.println("with 3 seconds between start and end of transaction");
System.out.println("Plus it will place additional log call and will enable reporting." );
return;
}
System.out.println( "Parameters are processed:" );
System.out.println( "\tnumberOfTxPerThread = " + numberOfTXPerThread );
System.out.println( "\tnumberOfThreads = " + numberOfThreads );
System.out.println( "\tlog = " + log );
System.out.println( "\tenable = " + enable );
System.out.println( "\tsecsToDelay = " + secsToDelay );
// cause initialization of a PerformanceDataReporter class
{
PerformanceDataReporter pReporter = new PerformanceDataReporter();
pReporter.enableReporting();
}
TestTXApi t = new TestTXApi( );
System.out.println( "\nAbout to start ..." );
t.prepareTests( numberOfTXPerThread, numberOfThreads, log, enable, secsToDelay );
long startTime = System.currentTimeMillis();
t.runTests( numberOfThreads );
// wait for threads to complete
for ( int i = 0; i &lt; numberOfThreads; i++ )
try
{
thread[i].join( );
} catch(Exception e)
{
System.out.println( "***Exception \"" + e + "\" while joining thread " + i );
}
long endTime = System.currentTimeMillis();
System.out.println( "\nTest runtime for " + ( numberOfTXPerThread * numberOfThreads) +
" TXs was " + ( endTime - startTime ) + " msec" );
}/* main() */
private void prepareTests( int numberOfTxPerThread,
int numberOfThreads, boolean log,
boolean enable, int secsToDelay )
{
System.out.println( "Creating " + numberOfThreads + " threads");
thread = new TestTXApiThread[numberOfThreads];
for ( int i = 0; i &lt; numberOfThreads; i++ )
thread[i] = new TestTXApiThread( i, numberOfTxPerThread,
log, enable, secsToDelay );
}/* prepareTests() */
private void runTests( int numberOfThreads )
{
for ( int i = 0; i &lt; numberOfThreads; i++ )
thread[i].start( );
}/* runTests() */
private class TestTXApiThread extends Thread
{
private int ordinal;
private int numberOfTxPerThread;
private boolean log;
private boolean enable;
private int secsToDelay;
private PerformanceDataReporter pReporter;
private long timeStamp[];
private long userCounters[];
public TestTXApiThread( int ordinal, int numberOfTxPerThread,
boolean log, boolean enable, int secsToDelay )
{
super();
this.ordinal = ordinal;
this.numberOfTxPerThread = numberOfTxPerThread;
this.log = log;
this.enable = enable;
this.secsToDelay = secsToDelay;
pReporter = new PerformanceDataReporter( false );
if ( enable )
pReporter.enableReporting();
timeStamp = new long[1];
userCounters = new long[16];
for ( int i = 0; i &lt; 16; i++ )
userCounters[i] = i;
}/* constructor */
public void run()
{
int i;
for ( i = 0; i &lt; numberOfTxPerThread; i++ )
{
pReporter.startTransaction( TxTypeArray[i%20], i, TxTypeArray[i%20], 20, timeStamp );
// pReporter.startTransaction( TxTypeArray[i%20], i, TxTypeString[i%20], timeStamp );
if ( log )
pReporter.logTransaction( TxTypeArray[i%20], i, TxTypeArray[i%20], 20 );
// pReporter.logTransaction( TxTypeArray[i%20], i, TxTypeString[i%20] );
if (secsToDelay &gt; 0)
try
{
Thread.sleep(secsToDelay * 1000);
} catch(Exception e) { }
pReporter.endTransaction( TxTypeArray[i%20], i, TxTypeArray[i%20], 20, timeStamp,
userCounters );
// pReporter.endTransaction( TxTypeArray[i%20], i, TxTypeString[i%20], timeStamp,
// userCounters );
}
}/* run() */
}/* class TestTXApiThread */
}/* class TestTXApi */
</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzahxcollservusertran.htm" title="Collection Services and performance explorer collect performance data that you define in your applications.">User-defined transactions</a></div>
</div>
</div>
</body>
</html>