UNIX: Java Application Development

Printer-friendly version

This appendix gives platform-specific details about developing Objectivity for Java applications on a UNIX platform. You should use this appendix in conjunction with the Objectivity for Java Programmer’s Guide.

This appendix provides information about:

Note: If you want to learn how to use various Objectivity for Java features, consider downloading and running some of the sample Java applications.

Application Programming Issues

Signal Handling

The Objectivity/DB predefined signal handler catches the following UNIX signals: SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGBUS, SIGSEGV, SIGHUP, SIGTERM, SIGEMT, and SIGTRAP.

By default, Objectivity for Java does not install the Objectivity/DB signal handler because some Java runtime environments do not support chaining of signal handlers. In such cases, installing the Objectivity/DB signal handler results in a segmentation violation rather than an orderly Java VM shutdown.

On the hpuxia64, linux86_64, linux86gcc3, solaris7, and sparc64 architectures, you can install the Objectivity/DB signal handler if you use a JDK which supports signal-chaining. To use this functionality, you must set the LD_PRELOAD environment variable as follows:

  • On linux86gcc3, solaris7, and sparc64, set LD_PRELOAD to <libjvm.so dir>/libjsig.so. This shared library must be loaded before libc/libthread/libpthread.
  • On hpuxia64, set LD_PRELOAD to <libjvm.so dir>/libjsig.so. This shared library must be loaded before libc.

For more information, see the vendor’s release notes for the JDK.

As an alternative to installing the Objectivity/DB signal handler, you can turn off some or all signals. See the section on the Objectivity/DB signal handler in "Controlling Interaction With Objectivity/DB" in the Objectivity for Java Programmer’s Guide.

File-Descriptor Limit

When running multithreaded programs with large numbers of threads, your process may reach the file-descriptor limit. When this limit is reached, the Java virtual machine unloads classes, and, at a later time, may report that it cannot find the definition of a class. Alternatively, Objectivity for Java operations may fail, with the cause being the inability to obtain a file descriptor.

To eliminate these errors, you should increase the file-descriptor limit. The csh and ksh commands to increase the limit are shown below. If you still experience errors, you should increase the limit incrementally.

Example

csh:

limit descriptors 256 

ksh:

ulimit -n 256  

Finalizing Objects in JDK 1.6

If you are developing an Objectivity for Java application using Sun JDK 1.6, you should be aware of the following JDK defect reported in the Sun Developer Network bug database:

Java objects created in JNI using AllocObject are not finalized
      

This defect affects your application if any of your persistence-capable classes defines a finalize() method.

The workaround is to add a default constructor that simply creates an empty object of the class.

Example

public class PCclass extends ooObj { 
  //...
      
  // If this exists...
  protected void finalize() {
  }
 
  // ... you must add this...
  public PCclass() { // Construct a dataless object
  }     
}      

Java Command Line Options

Stack Size

The default maximum native stack size allocated by the Java virtual machine for any thread (including the main thread) is platform-specific. In general, these default values are inadequate for Objectivity for Java. An inadequate stack size may cause an Objectivity for Java application to terminate with a segmentation violation for no apparent reason.

You change the default thread stack size for the Java virtual machine with the option:

-Xsssize     

where

size Number of bytes. To specify kilobytes or megabytes, append size with k or m, respectively.

Example

To specify a stack size of 2 megabytes:

% java -Xss2m classname 

Memory Requirements

If an Objectivity for Java application encounters java.lang.OutOfMemory errors, you can increase the amount of memory for the Java virtual machine with either or both of the following options:

-Xmssize Sets the initial memory size.
-Xmxsize Sets the maximum memory size.

where

size Number of bytes. To specify kilobytes or megabytes, append size with k or m, respectively.

HP-UX Architectures

To run an Objectivity for Java application that uses Objectivity/DB libraries on hpuxia64, you must set the -V2 option. This enables the application to load Objectivity/DB libraries compiled with the -AA flag.

64-bit Architectures

To run an application on sparc64, hpuxia64, or solaris86_64, you must specify the -d64 option. This uses the 64-bit data model of the Java virtual machine instead of the default 32-bit data model.

Date: 
Monday, August 20, 2012
Product: 
Objectivity/DB
Version: 
11.0