Threading in a class within a class?

Discussion in 'Java' started by ohaya, Jul 25, 2005.

  1. ohaya

    ohaya Guest

    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
    ohaya, Jul 25, 2005
    #1
    1. Advertising

  2. ohaya wrote:
    >
    > 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
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
    Thomas Hawtin, Jul 25, 2005
    #2
    1. Advertising

  3. ohaya

    ohaya Guest

    Thomas,

    Comments interspersed below...

    Jim


    Thomas Hawtin wrote:
    >
    > ohaya wrote:
    > >
    > > 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.


    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
    ohaya, Jul 25, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    337
  2. Replies:
    9
    Views:
    1,014
    Mark Space
    Dec 29, 2007
  3. Steven Woody
    Replies:
    0
    Views:
    394
    Steven Woody
    Jan 9, 2009
  4. Steven Woody
    Replies:
    0
    Views:
    435
    Steven Woody
    Jan 9, 2009
  5. Shoff

    Threading within a service

    Shoff, Apr 5, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    94
    news.icon.co.za
    Apr 5, 2004
Loading...

Share This Page