JDK 5 File/Stream Read Timeout API in an MDB

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 native 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.

Need Your Help

JAVA - Changing method return type from void to String instantly creates 'dead' code?

java variables types return global

I wrote a class a while back, which gets a specific set of values from specific XML files. It can then print the results in Console and it works just fine.

Removing android-support-v7-appcompat

android eclipse android-actionbar

I was using the Android developer guide to learn. On my first run, I ran into a number of problems setting up the v7 appcompat library which caused more errors for the next steps ahead of the guide...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.