18
Thu, Apr
5 New Articles

Make Your iSeries Java Applications Perform

Java
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Do you like to bet on horse racing? Do you like your chances with a horse that has 20-to-1 odds or 10-to-1 odds? The thing that makes horse racing so interesting is that you don't know which horse is going to win the race. You may know which horse is favored, but you really don't know which one will outperform all the others on any given day.

Unfortunately, this is sometimes the case with a Java application that runs on the iSeries. But you want your application to run at top speed every time it runs. There should be no chance involved. The odds of your Java application running at a high performance rate should always be even--one to one.

A Java programmer new to the iSeries server simply creates a Java program on a PC by compiling it and putting all of the class files into a Java ARchive (JAR) file. The JAR file is transferred to a directory on the iSeries server, and then the programmer goes into Qshell and enters the cd command to the directory where the JAR file was transferred. Once in the directory, the Java command is used to run the application. The RUNJVA CL command is another way of starting a Java application.

For example, I created a simple Hello.java program that was compiled and put into a hello.jar file. The hello.jar file was transferred into a directory called "test" on an OS/400 V5R2 iSeries system. Instead of using the Qshell command, I used the RUNJVA command. I entered the following on the iSeries command line:

RUNJVA CLASS(com.test.Hello) CLASSPATH('/test/hello.jar')

Once the RUNJVA command was run, it took only a couple of seconds for the application to start and complete. Realize that the hello.jar file was only 707 bytes and had no dependency on other JAR files. Many times, applications use class files from other JAR files. When this occurs, the other JAR files must be added to the classpath.

After this, I thought it was pretty easy to run Java applications on the iSeries server. I simply placed my class files into a JAR and then used the RUNJVA command, pointing only to the main class file and the JAR file that held all of my class files.

Then, I created another application with a JAR file of 689,210 bytes. The application listened for XML messages that were sent on a data queue, and then performed specific actions on the server, depending on the message. This application was dependent on five other JAR files that were in the IFS. I used the RUNJVA command, specifying my main class file within the CLASS parameter and my dependent JAR files in the CLASSPATH parameter:

RUNJVA CLASS(com.test..ApplicationMain) 
CLASSPATH('/test/app.jar:/test/xercesImpl.jar:
/test/xmlParserAPis.jar:
/qibm/proddata/os400/jt400/lib/jt400Native.jar:
/qibm/proddata/os400/able/able.jar:
/qibm/proddata/os400/able/antlr.jar:
/qibm/proddata/os400/able/Jlog.jar') 

Unfortunately, when running this Java application, the program took about one minute to start. Unacceptable! And after the application started, it took even longer to complete. I found a number of ways to speed up Java applications running on the iSeries server.

Warp Speed!

Certain parameters within the RUNJVA program can improve application performance. The default values of *OPTIMIZE for the interpret parameter and *JIT for the optimize parameter allow optimization to occur while your Java application is running.

The first time a Java application is run using the default values, the classes in the JAR file must be verified. The verification step can be fairly resource-expensive and time-consuming, and this is why my application ran so slowly in the example above. The result of the verification step in the internal form of the classes is used by the JVM and is attached to the JAR file. Any subsequent time the application is run, this pre-verified data is checked to see if it is current with the class in the JAR file. If it is, the JVM will use this data, and the application will run faster than it did the first time.

When you use the *JIT parameter, statistics are kept for each method that's being called within your Java application. Once the value for the Java system property, os400.jit.mmi.threshold, is reached, optimization occurs only for that method. The default and recommended value for the os400.jit.mmi.threshold is set to 2000. This optimizes only the methods that are called most often within your Java application.

If your application uses a custom class loader, you can use the os400.define.class.cache Java system property to improve the start-up time of your application. Every time your application starts, classes loaded by a custom class loader must be verified. Using the os400.define.class.cashe property allows the verified classes to be saved and used the next time the application is run. This is very similar to the mechanism used by the default Java class loaders.

Many Java programmers create their own custom class loaders. One reason is for security purposes. They want their applications to load only the classes within their JAR files and don't want to allow the capability of someone else loading a class file that might corrupt their applications. Some Java programmers like the capability of allowing their applications to add classes dynamically while the application is running, so they implement their own custom class loader with additional security. This enables programmers to add functionality to their applications without shutting down the application.

The value of the os400.define.class.cache.file should be the name of a valid JAR file. The JAR file must contain a valid JAR directory, but it must have no other contents except a single member within the JAR file. An example of the JAR file is located in the /qibm/proddata/Java400 directory called QDefineClassCache.jar. I created my custom class loader within my application and used the os400.define.class.cache.file Java property, pointing to the /qibm/proddata/Java400/QDefineClassCache.jar file:

RUNJVA 
CLASS(FTPServerSocket) 
PARM(os400.define.class.cache.file 
'/qibm/proddata/Java400/QDefineClassCache.jar') CLASSPATH('/garbersb/FtpServerSocket.jar')
OPTIMIZE(*OPTIMIZE) INTERPRET(*JIT)

When I started the application for the first time with the os400.define.class.cache.file Java property, it took the same amount of time it would have if I hadn't specified the os400.define.class.cache.file Java property. However, the second time I started the application, it started quickly, thanks to my cached start-up classes.

At certain times, a Java application may run more slowly than normal in certain spots. When this occurs, many programmers examine their code and try to find out why. What's nice is that you can collect performance information for your Java applications by specifying the Java system property os400.enbpfrcol with a value of 1, 7, or any non-zero value. A value of 1 collects all of the procedure entry and exit performance data. A value of 7 collects procedure entry and exit data along with performance data after calls to external procedures. A non-zero value generates Java entry and exit data along with Java pre-call and post-call events. Once you enable performance collection, use the performance tools to collect information about your application. Many Java programmers gather this information to see how their program is executing and what methods are used most often. Once the performance data is collected, you can use the Performance Trace Data Visualizer (PTDV) tool, which allows you to view the performance trace information.

Another way to possibly increase performance is by using the Create Java Program (CRTJVAPGM) command, which allows you to optimize the JAR file, giving you choices of *INTERPRET, 10, 20, 30, or 40.

*INTERPRET pre-verifies the Java program and converts it to an internal form while the application is running. The pre-verification takes some time, which may cause your Java program to initially run slowly, depending on how big your JAR file is. When you use *INTERPRET, the size of your JAR file remains the same.

Using 10, 20, 30 or 40 optimizes the iSeries server's machine instructions. The following are detailed descriptions of the differences between 10, 20, 30 and 40. This information was taken from OS/400 help for the CRTJVAPGM:

  • 10--The Java program(s) will contain a compiled version of the class file byte codes but will have only minimal additional compiler optimization. Variables can be displayed and modified while debugging.
  • 20--The Java program(s) will contain a compiled version of the class file byte codes and will have some additional compiler optimization performed. Variables can be displayed but not modified while debugging.
  • 30--The Java program(s) will contain a compiled version of the class file byte codes and will have more compiler optimization performed than optimization level 20. During a debug session, user variables cannot be changed but can be displayed. The presented values may not be the current values of the variables.
  • 40--The Java program(s) will contain a compiled version of the class file byte codes and will perform more compiler optimization than optimization level 30. In addition, it includes optimization that disables call and instruction tracing. Optimization level 40 includes cross-class optimizations. In a small number of cases, the order in which static initializers are run for unrelated classes (not related by inheritance or containment) may be different than outlined in the static initialization specification. In addition, it includes optimization that disables call and instruction tracing.

Specifying 10, 20, 30, or 40 for optimization increases your applications' start-up performance. This however, also increases the allocated size of your Java program. For example, I put a 703 KB JAR file on the iSeries system. After optimizing the JAR file to 40, I saved the object to put on another iSeries system in order to avoid having to enter the CRTJVAPGM command again on the second iSeries system because it takes some time for the command to process to completion. I first created a save file called FTPSERVER in library GARBERSB. I then issued the following command to save my JAR file into a saved file:

SAV DEV('/QSYS.LIB/GARBERSB.LIB/FTPSERVER.FILE') OBJ('/garbersb/FTPServerSocket.jar)

The FTPServerSocket.jar file within the saved file totaled 11,207 KB. As you can see, optimization increased the size of the JAR file.

Once I transferred the saved file onto the second system, I restored it in the same directory by using the following command:

RST DEV('/QSYS.LIB/GARBERSB.LIB/FTPSERVER.FILE') OBJ('/garbersb/FTPServerSocket.jar)

After I ran that command, the FTPServerSocket.jar file was restored. When I ran the Java application on the second system, it started right away, thanks to the optimization.

You can also specify other JAR files that are associated to this application within the classpath parameter, along with the Java Developer Kit (JDK) version. This allows the JDK you're running, along with other dependent JAR files, to function as if it is one bound application. Using CRTJVAPGM should increase your application's start-up speed and improve its overall performance.

I optimized the aforementioned JAR file specifying the 1.4.1 JDK and a classpath pointing to five other JAR files upon which my application was dependent. It took around 30 minutes for the CRTJVAPGM command process. As you can see, to make your Java application run faster, you must spend time up front optimizing your application for optimal performance.

One other thing that's nice about the CRTJVAPGM command is that you can specify adopt authority for your Java application. This allows the owner of the JAR file that was put on the system to be the application's owner. Simply specify *YES for the Use Adopt Authority parameter and *OWNER for the User Profile parameter. Doing this adds security to your application because it gives you the capability of running your Java application underneath a defined user profile that doesn't have a password associated with it. (Note: When using *JIT, this isn't possible.)

So, what are you supposed to use when creating Java applications for optimal performance? Benchmark tests show that applications using *JIT outperform applications using an optimization of 40 by up to 20%. Using *JIT is also more efficient because only the most frequently used methods will be turned into machine code. However, when you use *JIT, starting your Java application will be a little slower than with optimization levels 10, 20, 30, or 40. If your application uses a custom class loader, specifying the os400.define.class.cache Java system property can significantly improve the loading of the classes that it loads. If additional security is required within your Java application, consider using the CRTJVAPGM command and specifying adopt authority. It strictly depends on your application. By knowing the different ways to optimize your Java application on the iSeries, there is no need to worry about what your odds will be when it runs. They will always be one to one.

Benjamin Garbers is a Software Engineer within the Rochester Support Center. He is currently developing Internet applications for IBM's iSeries Technical Web site.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: