Cleaning up a session
Applications that use the 1010data Java SDK must manually clean up their 1010data
Insights Platform sessions after use. You can do this using the logout
method.
The Session
class contains a logout
method, which releases
the session when it is invoked. Depending on the login type that was used to create the
session, there are a few different ways the Insights Platform session might be cleaned
up. If you are a single user logged in with LoginType.POSSESS
, the
platform session continues to run. If you're a single user logged in with
LoginType.KILL
or LoginType.NOKILL
, the session is
terminated. A SAM pool user's platform session is released back into the pool.
Cleaning up a platform session when it is no longer needed is particularly important if
you have multiple users sharing a pool of IDs (SAM pool). The Java runtime does not
guarantee that destructors are called when the program is terminated. Additionally,
waiting for the garbage collector to clean up Session
objects may
result in a pool that appears fully utilized, but is waiting for
Session
objects to be destroyed. For more information about SAM
pools, see Shared Access Management (SAM).
In this example, the logout
method is used to clean up the session. To
ensure that the session is cleaned up afterward, the
try
/finally
statement is implemented with
testSession.logout();
. The
try
/finally
idiom guarantees that when you're done
with a session it gets properly deallocated.
import com.tentendata.javasdk1010v2.*; public class DocumentationExample { public static void printRows(Row r) { System.out.println(r); } public static void main(String[] args) { String gateway = "https://www2.1010data.com/cgi-bin/gw.k"; String user = "[USER_NAME]"; String pwd = "[USER_PASSWORD]"; String ops = "<sel value=\"(between(i_;1;10))\"/>"; try { Session testSession = new Session(gateway, user, pwd, LoginType.POSSESS); Query exampleQuery = new Query(testSession, path, ops); ResultSet results = exampleQuery.run(); for (long i = 0; i < results.numRows(); i++) { printRows(results.row(i)); } } finally { testSession.logout(); } } }
[USER_NAME]
and
[USER_PASSWORD]
are placeholders for
valid Insights Platform user name and password.