Re: how to get Process object from a thread (Runnable)
Marteno Rodia wrote:
On May 26, 6:51 pm, Daniel <dan...@proghowto.com> wrote:
Please clarify:
- you got some functionality
yes, definately
- you want it multithreaded or to run in a separate thread
To be precise, I have a multi-threaded application, and I want to
supress messages just for a part of one thread. The code which is
executed here hasn't been written by me.
- you want your threads to share an object of class Process that will
serve the purpose you mentioned.
I want to get a Process object just for this part of one of my
threads. I could launch another Thread for it, but the problem is
still I cannot get the Process object.
As has already been pointed out to you the process associated with each thread
within the JVM is the JVM itself. Since you already have direct access to the
input/output streams of the JVM via System.out/System.in/System.err you don't
need a Process to get these Streams. However, those System streams are shared
between all threads, so you can't redirect them just for some code executed by
a thread, they will be redirected for all threads for the duration of the
redirect.
***
The trick with loggers is also not a good idea, because I don't want
to/can't modify not my own code.
Then I'm pretty sure you can't do what you are attempting to do by any simple
means.
You may be able to implement your own class to handle the output by extending
PrintStream so it could replace System.out/err. You would need to devise your
own mechanism within that class for redirecting only the output generated by
the code you haven't written. But don't ask me how...
--
Nigel Wade