Threading in a class within a class?

O

ohaya

Hi,

I'm working on developing an extension to a commercial server product.
The base product is written in Java, and we don't have access to the
source, but they do provide an extension API from their product that I
am coding against. Basically this API involves us creating a class
with several methods in it, including an init() method which the main
server code calls during startup.

I originally had a basic extension working, but I needed to have the
extension take in some console input (a password) without having the
input display. While researching this, I found this article:

http://java.sun.com/features/2002/09/pword_mask.html

which uses threads to 'mask' console input. I first implemented a
small standalone app that does this, and this app works fine when run
on both Windows and Solaris, so I then incorporated the code into my
extension's init() code.

When I tested on my Windows test system, this worked fine. When the
server starts, I could see my extension's init() method being called,
and then I got a prompt and was able to enter input on the console
without it being displayed.

I then moved my extension over to Solaris, and it didn't work. I can
see my extension's init() method being called, but it looks like right
about the point where the init() method tries to instantiate a thread,
basically nothing happens.

Again, this same code works fine on Windows.

I suspect that, for some reason, creating/using a thread within my
class may be be "interfering" with threading that the server itself is
doing. The fact that this is only a problem on Solaris, gives me some
hope that I may be able to make this work on Solaris, but I was hoping
someone here might be able to shed some light on this problem.

Thanks,
Jim
 
T

Thomas Hawtin

ohaya said:
http://java.sun.com/features/2002/09/pword_mask.html

which uses threads to 'mask' console input. I first implemented a
small standalone app that does this, and this app works fine when run
on both Windows and Solaris, so I then incorporated the code into my
extension's init() code.
I suspect that, for some reason, creating/using a thread within my
class may be be "interfering" with threading that the server itself is
doing. The fact that this is only a problem on Solaris, gives me some
hope that I may be able to make this work on Solaris, but I was hoping
someone here might be able to shed some light on this problem.

If the thread is created but isn't actually running, I guess most likely
is that it's not at high enough priority. Try setting the priority to
Thread.MAX_PRIORITY before starting the thread. Note in that code stop
should be volatile, but something better ought to be done to stop the
thread after enter has been pressed.

Are you sure that System.out has not been redirected?

There's probably better solutions in UNIX. If the terminal supports ANSI
colours, switching the foreground and background to the same colour may
work (although I think on some terminals it is distinguishable).

Tom Hawtin
 
O

ohaya

Thomas,

Comments interspersed below...

Jim


Thomas said:
If the thread is created but isn't actually running, I guess most likely
is that it's not at high enough priority. Try setting the priority to
Thread.MAX_PRIORITY before starting the thread.

Thanks, I'd like to give that (setting the thread priority) a try. Were
you suggesting something like the following in PasswordField:

..
..
Thread thread = new Thread(maskingthread);
thread.setPriority(Thread.MAX_PRIORITY);
thread.start();
..
..

??


Note in that code stop
should be volatile, but something better ought to be done to stop the
thread after enter has been pressed.

Did you mean that in "class MaskingThread", the boolean "stop" should
be:

private volatile boolean stop = false;

instead of:

private boolean stop = false;

??



Are you sure that System.out has not been redirected?

I'm pretty sure that was the case...

There's probably better solutions in UNIX. If the terminal supports ANSI
colours, switching the foreground and background to the same colour may
work (although I think on some terminals it is distinguishable).

That was one of the ideas that I had considered, but I wanted to (hoped)
that I could come up with a mechanism that would work on both Windows
and Solaris...

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top