<title css='default.css'>The Static Statement</title>
<macro name=isolation><a href='isolation.html'>isolation</a></macro>

<p>JSP files and the files they import execute in isolation from all
other requests to the same files.  In addition, their statements
are reevaluated for each request.  The static statement lets the
developer execute a statement only once or to share information
between requests</p>
<def>
static <var>statement</var>;
</def>

<var>statement</var> is executed as soon as the file is parsed.
During subsequent requests, the statement is not reevaluated.

<p>Requests are still <a href='isolation.html'>isolated</a> from
each other.  All JavaScript objects created or modified in a
<code>static</code> statement are copied for each request.  Since
<a href="wrap.html">wrapped</a> Java objects are not copied,
developers can use <code>static</code> statements in combination with
<a href="wrap.html">wrapped</a> Java objects to create application
objects.</p>

<p>In general, Java used as application objects will need <a
href='synchronization.html'>synchronization</a> to keep the state
consistent between request threads</p>

<example>
&lt;%
static {
  application = new caucho.vfs.MemoryFilesystem();
  application.object = 3;
}

synchronize (application) {
  value = application.object++;
}

%&gt;

&lt;h1&gt;You are visitor &lt;%= value %&gt; &lt;h1&gt;
</example>
