Static And Non-Final Variables In A Java Routine - IBM DB2 Manual

Table of Contents

Advertisement

|
|
|
|
|
|
|

Static and non-final variables in a Java routine

– SET CONNECTION
v Routine parameters have different mappings to host language data types than
the mappings of routine parameters to host language parameters for other
languages.
v The technique for returning result sets from Java stored procedures is different
from the technique for returning result sets in other stored procedures.
v When a Java routine executes, Java dynamically loads classes when new class
references occur in the class that is being executed. During the class loading
process, a java.lang.ClassNotFoundException or
java.lang.NoClassDefFoundError can be thrown. These failures can occur
whether Java looks for the class in an installed JAR or in the CLASSPATH. If the
Java routine does not catch these errors and exceptions, the routine terminates
and an SQL error condition is reported.
Related concepts
"Differences between Java routines and stand-alone Java programs" on page
176
"Creating an external stored procedure" (DB2 Application Programming and
SQL Guide)
"Writing an external user-defined function" (DB2 Application Programming and
SQL Guide)
Related tasks
"Writing a Java stored procedure to return result sets" on page 178
Related reference
"Data types that map to database data types in Java applications" on page 193
Using static and non-final variables can cause problems for Java routines.
The reasons for those problems are:
v Use of variables that are static and non-final reduces portability.
Because the ANSI/ISO standard does not include support for static and
non-final variables, different database products might process those variables
differently.
v A sequence of routine invocations is not necessarily processed by the same JVM,
and static variable values are not shared among different JVMs.
For example, suppose that two stored procedures, INITIALIZE and PROCESS,
use the same static variable, sv1. INITIALIZE sets the value of sv1, and
PROCESS depends on the value of sv1. If INITIALIZE runs in one JVM, and
then PROCESS runs in another JVM, sv1 in PROCESS does not contain the value
that INTIALIZE set.
Specifying NUMTCB=1 in the WLM-established stored process space startup
procedure is not sufficient to guarantee that a sequence of routine invocations go
to the same JVM. Under load, multiple stored procedure address spaces are
initiated, and each address space has its own JVM. Multiple invocations might
be directed to multiple address spaces.
v In Java, the static variables for a class are initialized or reset whenever the class
is loaded. However, for Java routines, it is difficult to know when initialization
or reset of static variables occurs.
Chapter 5. Java stored procedures and user-defined functions
177

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents