How Should Static Variables Be Used In Java Batch Programs?

(Doc ID 1081090.1)

Last updated on OCTOBER 18, 2016

Applies to:

Oracle Utilities Customer Care and Billing - Version: 2.0.1 to 2.3.0 - Release: 2.0 to 2.3
Information in this document applies to any platform.


Why are values sometimes saved correct or incorrectly when stored in static variables during a batch run specifically batch executed using thread pool?

EXAMPLE 1: Static Variable used as counter

X is a static variable

Start Batch Run 1: X = 0, 0 is the default value for integer
End Batch Run 1: X = 5
Start Batch Run 2: X = 5

JVM threadpools are started each time for the batch run but the threadpool seems to remember the previous value.

Why does X retain its value from the previous batch run?

EXAMPLE 2: Static Variable used to store batch parameter value

X is a static variable

Batch Parameter = A
Batch Run 1: X = A

Batch Parameter = B
Batch Run 2: X can either be A, B or blank.

The batch parameter Report Name value was change so when the batch was executed, the batch raised a null pointer exception since the static variable didn't have any value. But when the batch was executed again, it now has a value.

Why is that there are times when the variable stores different value?


Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms