Some questions
riki1512 May 23, 2003 9:37 AMHi,
I'm wondering that i can't find this question anywhere: How can I automatically instantiate one Bean when the Server is started or the .jar file is deployed ? Maybe i can't find it because it makes no sense ?
I've got to manage some socket-connections and I'm using the beans because every connection then is automatically managed in a thread. I've got a Connection-Pool, and the beans only work as a facade to ask the pool for one connection. That works nice, but I have a static constructor in the pool to open the socket-connections i need. The first-time the Connection-Pool is loaded by the VM, and that goes with the first client sending a Message using my beans, the sockets are opened. That is not really clean. What do I have to do that one Bean is instantiated at the server-start or after deploying ? Or better that a static-constructor of a class is started at the Server-start - or after deploying.
On the outgoing side, i have 4 or more connections, so i have a ConnectionPool, a static Hashtable where i manage the Sockets.
But on the ingoing side, there must be only one connection, one socket. (Connection to legacy system). It sounds simple, but how can i get sure that that Connection is opened only once ? I can't use a static constructor there because I need a 'normal' constructor with parameters. I can't build a Pool around with a static constructor again because there is only one connection and so that would by a poor elusion...
It really sounds easy but i can't solve it. I could add the incoming connection as a static field in the Pool, beside the Hashtable. But I can't start the inStream.read-method because this method blocks the thread. I have to start it from another bean to use another thread (and I don't want to programme a thread because they all say that it's so nice using the beans because you don't have to worry about threads...). But how can I start the inStream.read - method only once over a bean ? Maybe at the start of the server - somehow automatically ? But makes it really sense that one bean would then exist as long as i read Messages over the InputStream from the Socket ?
Maybe there is a very simple solution or it even is'nt really a problem but i'ts friday, I slept only 5 hours and my brain is full - or empty...
Any answers, please ?