How does the StreamBaseClient object use the java.util.Timer object?
book
Article ID: KB0076348
calendar_today
Updated On:
Description
How does the StreamBaseClient object use the java.util.Timer object?
Issue/Introduction
How does the StreamBaseClient object use the java.util.Timer object?
Resolution
The StreamBaseClient object creates one Timer object when the enableBuffering() method is called with bufferSize > 0 and flushInterval > 0.
- enableBuffering()
- enableBuffering() throws a StreamBaseException if called more than once with bufferSize > 0 during the lifetime of the StreamBaseClient.
- enableBuffering() is a public method, which is called only by custom code; StreamBase internal client code does not call this method.
- Timer object
- The Timer object is used to schedule a WakeAndFlushBuffer (which is a TimerTask) to run at intervals specified in milliseconds by flushInterval.
- The WakeAndFlushBuffer method flushes (directly enqueues to the server) any enqueued but still buffered tuples.
- If that flushing throws a StreamBaseException, or if the StreamBaseClient is closed, then the Timer is canceled.
- StreamBaseException
- The most likely cause of a StreamBaseException for flushing is some trouble with the underlying TCP connection between the client and server.
- finalizer() method
- Neither StreamBaseClient nor WakeAndFlushBuffer null out the reference to the Timer object explicitly. If your client application does not explicitly close() the StreamBaseClient, the timer may not get canceled expeditiously.
- If you construct and use a StreamBaseClient and then null out all references to it from the application, the JVM does a GC and calls the finalizer() method on that StreamBaseClient instance. In this situation, StreamBaseClient does not override finalizer().
- The JVM spec does not guarantee that the GC will ever call finalizer(). StreamBase client applications must be written to close() their StreamBaseClients explicitly (usually in a catch block or, perhaps even better, in a finally block). Close() can throw exceptions, if close() has already been called before on that StreamBaseClient.
Feedback
thumb_up
Yes
thumb_down
No