3.6.1.3. Context Creation Example

// Create a context that includes a connection and a session.
// Use try with resources to close the context when done.
try (JMSContext context = connectionFactory.createContext ();)
{
  // Create another context reusing the same connection.
  try (JMSContext another = context.createContext ();)
  {
    ...
  } catch (JMSRuntimeException ex) { ... }
} catch (JMSRuntimeException ex) { ... }