Is there a JDK 5 or older API for reading files and or reading streams with a timeout? Also, this API must be safe when wrapped inside an MDB. FYI: I have already looked into using the FutureResult, TimedCallable classes and the like; I have come to the conclusion that using these within in MDB is not advisable since 1. these are not JDK nativ开发者_JS百科e classes, and 2. threads are spawned inside the MDB; so I need another solution.
Also I would believe that any solution would require threading since there must be a thread that reads and one that manages the the timeliness of the read thread and blocks it if necessary. Therefore, would such a behavior be illegal inside an MDB? What if said API is native to the JDK will this make it safe to implement?
As you see from the InputStream API there is no general contract for this. However some Streams, like the InputStream you get from a socket, have a timeout behaviour, but this has to be configured on the socket.
AFAIK you can try to interrupt the reading Thread manually, by calling interrupt() on it, and hope that the underlying implementation of your Stream does not catch this without rethrowing it (A common mistake when using wait() on a monitor). This however has to be done in an extra thread, or by using the Future API you mentioned above. If you catch this InterruptedException, and handle it appropriately, you should have a fairly stable solution.
PS: What is an MDB? I only know this acronym for the Microsoft Database format used by Microsoft Access.
精彩评论