using JConsole - hangs and setOut issues

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

using JConsole - hangs and setOut issues

robert lytle
i'm trying to use JConsole, and i'm having two issues:
  1. hang/deadlock approximately 50% of the time
  2. output does not go to the console

I'm java-6 on linux. Here's my very simple class:  

public class Console2 extends javax.swing.JFrame {
    bsh.util.JConsole bconsole;
    bsh.Interpreter sh;
    public Console2() {

        bconsole = new bsh.util.JConsole();
        sh = new bsh.Interpreter(bconsole);
        new Thread(sh).start();

        this.setSize(600, 600);
        this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        this.getContentPane().add(bconsole);
    }
    public static void main(String args[]) {
        Console2 console = new Console2();
        console.setVisible(true);
    }
}

here's an even simpler one that shows the same behavior

public class Console3  {
    public static void main(String args[]) throws bsh.EvalError {
        bsh.Interpreter sh = new bsh.Interpreter();
        sh.eval( "desktop();" );
    }
}


in both cases, one of two things happens (approx 50/50)
  1. the gui works as expected
  2. the gui never appears and the command-line hangs
      control-c kills it in this case

if i add
  System.setOut( bconsole.getOut() );
then when it runs, the output goes to the right place, but i should be able to do
  sh.setOut( bconsole.getOut() );
this doesn't work (ie the output still goes to standard out, not to the gui window).


are other people seeing these problems ? any thoughts on how to "properly" use the JConsole ?

other than this issue, i think beanshell is great - easy to use, simple. i was looking for a shell
environ a while back and tried groovy. and then more recently jython. both are heavy with way too
much magic and nonsense. beanshell is just so damn elegant. and if i want to move a script into
true java, it's simple - just add a few types :)


seth




__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: using JConsole - hangs and setOut issues - SOLUTION

robert lytle
i solved my problem (see below) so i'm happy. but i haven't gotten any replies, which makes me
wonder if this list is dead. is there anybody out there ? normally the silence would make me think
that the project was dead, but it just works so _well_ that it's more likely there's just not much
need for the list, or people have gone elsewhere :)

enough rambling - here's my solution:
-----------------------------------------------------------------------------------------

ok - did a little more work today and found

http://www.ikayzo.org/confluence/pages/viewpage.action?pageId=23

which is a FAQ:    How can I use JConsole as an output terminal in my application?
on the wiki.

it (Daniel Leuck) says to create the console, then run the interpreter, and now everything just
works. thanks dan. here's the fixed class:


public class Console2 extends javax.swing.JFrame {
    bsh.util.JConsole bconsole;
    bsh.Interpreter sh;
    public Console2() {
        bconsole = new bsh.util.JConsole();
        this.setSize(600, 600);
        this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        this.getContentPane().add(bconsole);
    }
    public void run() {
        sh = new bsh.Interpreter(bconsole);
        sh.run();
    }
    public static void main(String args[]) {
        Console2 console = new Console2();
        console.setVisible(true);
        console.run();
    }
}





--- robert lytle <[hidden email]> wrote:

> i'm trying to use JConsole, and i'm having two issues:
>   1. hang/deadlock approximately 50% of the time
>   2. output does not go to the console
>
> I'm java-6 on linux. Here's my very simple class:  
>
> public class Console2 extends javax.swing.JFrame {
>     bsh.util.JConsole bconsole;
>     bsh.Interpreter sh;
>     public Console2() {
>
>         bconsole = new bsh.util.JConsole();
>         sh = new bsh.Interpreter(bconsole);
>         new Thread(sh).start();
>
>         this.setSize(600, 600);
>         this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
>         this.getContentPane().add(bconsole);
>     }
>     public static void main(String args[]) {
>         Console2 console = new Console2();
>         console.setVisible(true);
>     }
> }
>
> here's an even simpler one that shows the same behavior
>
> public class Console3  {
>     public static void main(String args[]) throws bsh.EvalError {
>         bsh.Interpreter sh = new bsh.Interpreter();
>         sh.eval( "desktop();" );
>     }
> }
>
>
> in both cases, one of two things happens (approx 50/50)
>   1. the gui works as expected
>   2. the gui never appears and the command-line hangs
>       control-c kills it in this case
>
> if i add
>   System.setOut( bconsole.getOut() );
> then when it runs, the output goes to the right place, but i should be able to do
>   sh.setOut( bconsole.getOut() );
> this doesn't work (ie the output still goes to standard out, not to the gui window).
>
>
> are other people seeing these problems ? any thoughts on how to "properly" use the JConsole ?
>
> other than this issue, i think beanshell is great - easy to use, simple. i was looking for a
> shell
> environ a while back and tried groovy. and then more recently jython. both are heavy with way
> too
> much magic and nonsense. beanshell is just so damn elegant. and if i want to move a script into
> true java, it's simple - just add a few types :)
>
>
> seth
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com 
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> Don't miss this year's exciting event. There's still time to save $100.
> Use priority code J8TL2D2.
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>



      ____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: using JConsole - hangs and setOut issues - SOLUTION

Alexey Zinger
Hi Robert,

The list is quiet, but not dead (though the project doesn't seem to be moving forward at the moment).  Normally there is a response to a question within a day or two, but sometimes the person finds out the solution first, as you have.

robert lytle <[hidden email]> wrote:
i solved my problem (see below) so i'm happy. but i haven't gotten any replies, which makes me
wonder if this list is dead. is there anybody out there ? normally the silence would make me think
that the project was dead, but it just works so _well_ that it's more likely there's just not much
need for the list, or people have gone elsewhere :)

enough rambling - here's my solution:
-----------------------------------------------------------------------------------------

ok - did a little more work today and found

http://www.ikayzo.org/confluence/pages/viewpage.action?pageId=23

which is a FAQ: How can I use JConsole as an output terminal in my application?
on the wiki.

it (Daniel Leuck) says to create the console, then run the interpreter, and now everything just
works. thanks dan. here's the fixed class:


public class Console2 extends javax.swing.JFrame {
bsh.util.JConsole bconsole;
bsh.Interpreter sh;
public Console2() {
bconsole = new bsh.util.JConsole();
this.setSize(600, 600);
this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
this.getContentPane().add(bconsole);
}
public void run() {
sh = new bsh.Interpreter(bconsole);
sh.run();
}
public static void main(String args[]) {
Console2 console = new Console2();
console.setVisible(true);
console.run();
}
}





--- robert lytle wrote:

> i'm trying to use JConsole, and i'm having two issues:
> 1. hang/deadlock approximately 50% of the time
> 2. output does not go to the console
>
> I'm java-6 on linux. Here's my very simple class:
>
> public class Console2 extends javax.swing.JFrame {
> bsh.util.JConsole bconsole;
> bsh.Interpreter sh;
> public Console2() {
>
> bconsole = new bsh.util.JConsole();
> sh = new bsh.Interpreter(bconsole);
> new Thread(sh).start();
>
> this.setSize(600, 600);
> this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
> this.getContentPane().add(bconsole);
> }
> public static void main(String args[]) {
> Console2 console = new Console2();
> console.setVisible(true);
> }
> }
>
> here's an even simpler one that shows the same behavior
>
> public class Console3 {
> public static void main(String args[]) throws bsh.EvalError {
> bsh.Interpreter sh = new bsh.Interpreter();
> sh.eval( "desktop();" );
> }
> }
>
>
> in both cases, one of two things happens (approx 50/50)
> 1. the gui works as expected
> 2. the gui never appears and the command-line hangs
> control-c kills it in this case
>
> if i add
> System.setOut( bconsole.getOut() );
> then when it runs, the output goes to the right place, but i should be able to do
> sh.setOut( bconsole.getOut() );
> this doesn't work (ie the output still goes to standard out, not to the gui window).
>
>
> are other people seeing these problems ? any thoughts on how to "properly" use the JConsole ?
>
> other than this issue, i think beanshell is great - easy to use, simple. i was looking for a
> shell
> environ a while back and tried groovy. and then more recently jython. both are heavy with way
> too
> much magic and nonsense. beanshell is just so damn elegant. and if i want to move a script into
> true java, it's simple - just add a few types :)
>
>
> seth
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> Don't miss this year's exciting event. There's still time to save $100.
> Use priority code J8TL2D2.
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>



____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users



Alexey
2001 Honda CBR600F4i (CCS)
1992 Kawasaki EX500
http://azinger.blogspot.com
http://bsheet.sourceforge.net
http://wcollage.sourceforge.net

between 0000-00-00 and 9999-99-99  
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users

Reply | Threaded
Open this post in threaded view
|

Re: using JConsole - hangs and setOut issues - SOLUTION

Daniel Leuck
In reply to this post by robert lytle
There hasn't been any active development for a while, but BeanShell is
still widely used.  I wrote a blog entry about hacking BeanShell with
JavaCC last week:
http://www.techhui.com/profiles/blog/show?id=1702911%3ABlogPost%3A10425

There is a JSR for BeanShell:
http://www.jcp.org/en/jsr/detail?id=274

On Tue, Apr 15, 2008 at 4:24 AM, robert lytle <[hidden email]> wrote:

> i solved my problem (see below) so i'm happy. but i haven't gotten any replies, which makes me
>  wonder if this list is dead. is there anybody out there ? normally the silence would make me think
>  that the project was dead, but it just works so _well_ that it's more likely there's just not much
>  need for the list, or people have gone elsewhere :)
>
>  enough rambling - here's my solution:
>  -----------------------------------------------------------------------------------------
>
>  ok - did a little more work today and found
>
>  http://www.ikayzo.org/confluence/pages/viewpage.action?pageId=23
>
>  which is a FAQ:    How can I use JConsole as an output terminal in my application?
>  on the wiki.
>
>  it (Daniel Leuck) says to create the console, then run the interpreter, and now everything just
>  works. thanks dan. here's the fixed class:
>
>
>  public class Console2 extends javax.swing.JFrame {
>     bsh.util.JConsole bconsole;
>     bsh.Interpreter sh;
>     public Console2() {
>         bconsole = new bsh.util.JConsole();
>         this.setSize(600, 600);
>         this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
>         this.getContentPane().add(bconsole);
>     }
>     public void run() {
>         sh = new bsh.Interpreter(bconsole);
>         sh.run();
>     }
>     public static void main(String args[]) {
>         Console2 console = new Console2();
>         console.setVisible(true);
>         console.run();
>     }
>  }
>
>
>
>
>
>  --- robert lytle <[hidden email]> wrote:
>
>  > i'm trying to use JConsole, and i'm having two issues:
>  >   1. hang/deadlock approximately 50% of the time
>  >   2. output does not go to the console
>  >
>  > I'm java-6 on linux. Here's my very simple class:
>  >
>  > public class Console2 extends javax.swing.JFrame {
>  >     bsh.util.JConsole bconsole;
>  >     bsh.Interpreter sh;
>  >     public Console2() {
>  >
>  >         bconsole = new bsh.util.JConsole();
>  >         sh = new bsh.Interpreter(bconsole);
>  >         new Thread(sh).start();
>  >
>  >         this.setSize(600, 600);
>  >         this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
>  >         this.getContentPane().add(bconsole);
>  >     }
>  >     public static void main(String args[]) {
>  >         Console2 console = new Console2();
>  >         console.setVisible(true);
>  >     }
>  > }
>  >
>  > here's an even simpler one that shows the same behavior
>  >
>  > public class Console3  {
>  >     public static void main(String args[]) throws bsh.EvalError {
>  >         bsh.Interpreter sh = new bsh.Interpreter();
>  >         sh.eval( "desktop();" );
>  >     }
>  > }
>  >
>  >
>  > in both cases, one of two things happens (approx 50/50)
>  >   1. the gui works as expected
>  >   2. the gui never appears and the command-line hangs
>  >       control-c kills it in this case
>  >
>  > if i add
>  >   System.setOut( bconsole.getOut() );
>  > then when it runs, the output goes to the right place, but i should be able to do
>  >   sh.setOut( bconsole.getOut() );
>  > this doesn't work (ie the output still goes to standard out, not to the gui window).
>  >
>  >
>  > are other people seeing these problems ? any thoughts on how to "properly" use the JConsole ?
>  >
>  > other than this issue, i think beanshell is great - easy to use, simple. i was looking for a
>  > shell
>  > environ a while back and tried groovy. and then more recently jython. both are heavy with way
>  > too
>  > much magic and nonsense. beanshell is just so damn elegant. and if i want to move a script into
>  > true java, it's simple - just add a few types :)
>  >
>  >
>  > seth
>  >
>  >
>  >
>  >
>  > __________________________________________________
>  > Do You Yahoo!?
>  > Tired of spam?  Yahoo! Mail has the best spam protection around
>  > http://mail.yahoo.com
>  >
>  > -------------------------------------------------------------------------
>  > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>  > Don't miss this year's exciting event. There's still time to save $100.
>  > Use priority code J8TL2D2.
>  > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>  > _______________________________________________
>  > Beanshell-users mailing list
>  > [hidden email]
>  > https://lists.sourceforge.net/lists/listinfo/beanshell-users
>  >
>
>
>
>       ____________________________________________________________________________________
>  Be a better friend, newshound, and
>  know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>
>  -------------------------------------------------------------------------
>  This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>  Don't miss this year's exciting event. There's still time to save $100.
>  Use priority code J8TL2D2.
>  http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>  _______________________________________________
>  Beanshell-users mailing list
>  [hidden email]
>  https://lists.sourceforge.net/lists/listinfo/beanshell-users
>



--
Daniel Leuck
President
Ikayzo, inc.
+1 (808) 539-3804 (US Direct)
+81 03-3655-2829 (Japan Direct)
+1 (808) 393-9119 (Mobile)
+1 (808) 591-1496 (Fax)
http://www.ikayzo.com
http://www.javaui.net

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: using JConsole - hangs and setOut issues - SOLUTION

robert lytle
great to hear, and a good entry for me - i'm doing matrixy stuff with bsh, though for now part of
what i like about bsh is that it keeps close to the java syntax


i still have one outstanding issue with the console. i want the output to go to the console, not
to stdout. if i use:
                System.setOut(bconsole.getOut());

everything works fine. but if i use:
                sh.setOut(bconsole.getOut());

the output still goes to stdout. any idea why this doesn't work "right" ?

also, i grabbed the svn and needed to change a few things to get it to build. not 100% sure that i
made the correct changes. a patch is attached - it's just a minor change (looks like javax.script
changed - bsh uses invoke, javax uses invokeFunction and invokeMethod )

i haven't tried stepping thru the code to see what setOut is doing, but if i don't hear anything,
i'll try that sometime


--- Daniel Leuck <[hidden email]> wrote:

> There hasn't been any active development for a while, but BeanShell is
> still widely used.  I wrote a blog entry about hacking BeanShell with
> JavaCC last week:
> http://www.techhui.com/profiles/blog/show?id=1702911%3ABlogPost%3A10425
>
> There is a JSR for BeanShell:
> http://www.jcp.org/en/jsr/detail?id=274
>
> On Tue, Apr 15, 2008 at 4:24 AM, robert lytle <[hidden email]> wrote:
> > i solved my problem (see below) so i'm happy. but i haven't gotten any replies, which makes me
> >  wonder if this list is dead. is there anybody out there ? normally the silence would make me
> think
> >  that the project was dead, but it just works so _well_ that it's more likely there's just not
> much
> >  need for the list, or people have gone elsewhere :)
> >
> >  enough rambling - here's my solution:
> >  -----------------------------------------------------------------------------------------
> >
> >  ok - did a little more work today and found
> >
> >  http://www.ikayzo.org/confluence/pages/viewpage.action?pageId=23
> >
> >  which is a FAQ:    How can I use JConsole as an output terminal in my application?
> >  on the wiki.
> >
> >  it (Daniel Leuck) says to create the console, then run the interpreter, and now everything
> just
> >  works. thanks dan. here's the fixed class:
> >
> >
> >  public class Console2 extends javax.swing.JFrame {
> >     bsh.util.JConsole bconsole;
> >     bsh.Interpreter sh;
> >     public Console2() {
> >         bconsole = new bsh.util.JConsole();
> >         this.setSize(600, 600);
> >         this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
> >         this.getContentPane().add(bconsole);
> >     }
> >     public void run() {
> >         sh = new bsh.Interpreter(bconsole);
> >         sh.run();
> >     }
> >     public static void main(String args[]) {
> >         Console2 console = new Console2();
> >         console.setVisible(true);
> >         console.run();
> >     }
> >  }
> >
> >
> >
> >
> >
> >  --- robert lytle <[hidden email]> wrote:
> >
> >  > i'm trying to use JConsole, and i'm having two issues:
> >  >   1. hang/deadlock approximately 50% of the time
> >  >   2. output does not go to the console
> >  >
> >  > I'm java-6 on linux. Here's my very simple class:
> >  >
> >  > public class Console2 extends javax.swing.JFrame {
> >  >     bsh.util.JConsole bconsole;
> >  >     bsh.Interpreter sh;
> >  >     public Console2() {
> >  >
> >  >         bconsole = new bsh.util.JConsole();
> >  >         sh = new bsh.Interpreter(bconsole);
> >  >         new Thread(sh).start();
> >  >
> >  >         this.setSize(600, 600);
> >  >         this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
> >  >         this.getContentPane().add(bconsole);
> >  >     }
> >  >     public static void main(String args[]) {
> >  >         Console2 console = new Console2();
> >  >         console.setVisible(true);
> >  >     }
> >  > }
> >  >
> >  > here's an even simpler one that shows the same behavior
> >  >
> >  > public class Console3  {
> >  >     public static void main(String args[]) throws bsh.EvalError {
> >  >         bsh.Interpreter sh = new bsh.Interpreter();
> >  >         sh.eval( "desktop();" );
> >  >     }
> >  > }
> >  >
> >  >
> >  > in both cases, one of two things happens (approx 50/50)
> >  >   1. the gui works as expected
> >  >   2. the gui never appears and the command-line hangs
> >  >       control-c kills it in this case
> >  >
> >  > if i add
> >  >   System.setOut( bconsole.getOut() );
> >  > then when it runs, the output goes to the right place, but i should be able to do
> >  >   sh.setOut( bconsole.getOut() );
> >  > this doesn't work (ie the output still goes to standard out, not to the gui window).
> >  >
> >  >
> >  > are other people seeing these problems ? any thoughts on how to "properly" use the JConsole
> ?
> >  >
> >  > other than this issue, i think beanshell is great - easy to use, simple. i was looking for
> a
> >  > shell
> >  > environ a while back and tried groovy. and then more recently jython. both are heavy with
> way
> >  > too
> >  > much magic and nonsense. beanshell is just so damn elegant. and if i want to move a script
> into
> >  > true java, it's simple - just add a few types :)
> >  >
> >  >
> >  > seth
> >  >
> >  >
> >  >
> >  >
> >  > __________________________________________________
> >  > Do You Yahoo!?
> >  > Tired of spam?  Yahoo! Mail has the best spam protection around
> >  > http://mail.yahoo.com
> >  >
> >  > -------------------------------------------------------------------------
> >  > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> >  > Don't miss this year's exciting event. There's still time to save $100.
> >  > Use priority code J8TL2D2.
> >  > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> >  > _______________________________________________
> >  > Beanshell-users mailing list
> >  > [hidden email]
> >  > https://lists.sourceforge.net/lists/listinfo/beanshell-users
> >  >
> >
> >
> >
> >       ____________________________________________________________________________________
> >  Be a better friend, newshound, and
> >  know-it-all with Yahoo! Mobile.  Try it now.
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
> >
> >  -------------------------------------------------------------------------
> >  This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> >  Don't miss this year's exciting event. There's still time to save $100.
> >  Use priority code J8TL2D2.
> >  http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> >  _______________________________________________
> >  Beanshell-users mailing list
> >  [hidden email]
> >  https://lists.sourceforge.net/lists/listinfo/beanshell-users
> >
>
>
>
> --
> Daniel Leuck
> President
> Ikayzo, inc.
> +1 (808) 539-3804 (US Direct)
> +81 03-3655-2829 (Japan Direct)
> +1 (808) 393-9119 (Mobile)
> +1 (808) 591-1496 (Fax)
> http://www.ikayzo.com
> http://www.javaui.net
>


      ____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
Index: engine/src/TestBshScriptEngine.java
===================================================================
--- engine/src/TestBshScriptEngine.java (revision 42)
+++ engine/src/TestBshScriptEngine.java (working copy)
@@ -43,7 +43,7 @@
  engine.eval("foo() { return foo+1; }");
  // invoke a method
  Invocable invocable = (Invocable) engine;
- int foo = (Integer)invocable.invoke( "foo" );
+ int foo = (Integer)invocable.invokeFunction( "foo" );
  assertTrue( foo == 43 );
 
  // get interface
@@ -58,7 +58,7 @@
  engine.eval(
  "flag2=false; myObj() { run() { flag2=true; } return this; }");
  assertTrue( (Boolean)engine.get("flag2") == false );
- Object scriptedObject = invocable.invoke("myObj");
+ Object scriptedObject = invocable.invokeFunction("myObj");
  assertTrue( scriptedObject instanceof bsh.This );
  runnable =
  (Runnable)invocable.getInterface( scriptedObject, Runnable.class );
Index: engine/src/bsh/engine/BshScriptEngine.java
===================================================================
--- engine/src/bsh/engine/BshScriptEngine.java (revision 42)
+++ engine/src/bsh/engine/BshScriptEngine.java (working copy)
@@ -5,6 +5,7 @@
 import javax.script.*;
 import bsh.*;
 import static javax.script.ScriptContext.*;
+import bsh.engine.*;
 
 /*
  Notes
@@ -17,7 +18,7 @@
  // engine scope map under this key.
  static final String engineNameSpaceKey = "org_beanshell_engine_namespace";
 
- private BshScriptEngineFactory factory;
+ private bsh.engine.BshScriptEngineFactory factory;
  private bsh.Interpreter interpreter;
 
  public BshScriptEngine() {
@@ -198,7 +199,7 @@
  * types cannot be found.
  * @throws NullPointerException if method name is null.
  */
- public Object invoke( Object thiz, String name, Object... args ) throws ScriptException, NoSuchMethodException
+ public Object invokeMethod( Object thiz, String name, Object... args ) throws ScriptException, NoSuchMethodException
  {
  if ( ! (thiz instanceof bsh.This) )
  throw new ScriptException( "Illegal objec type: " +thiz.getClass() );
@@ -242,10 +243,10 @@
  * argument types cannot be found.
  * @throws NullPointerException if method name is null.
  */
- public Object invoke( String name, Object... args )
+ public Object invokeFunction( String name, Object... args )
  throws ScriptException, NoSuchMethodException
  {
- return invoke( getGlobal(), name, args );
+ return invokeMethod( getGlobal(), name, args );
  }
 
  /**

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: using JConsole - hangs and setOut issues

ecor6633
In reply to this post by robert lytle
Thanks a lot for that example of using a Jconsole. I can now successfuly use my own console. The problem is how to stop the Interpreter Thread... ?

I will have to use my Jconsole in an OSGi framework in the future so it's totally impossible to use System.exit(0);. I have to send an EOF so that the Thread can end its loop.

Here is the code i used :
console = new JConsole();
interpreter = new Interpreter(console, namespace);
interpreter.setExitOnEOF(false);
interpreter.setShowResults(true);
interpreteurThread = new Thread(interpreter);
interpreteurThread.start();

I already tried closing input or output streams, passing \u0004 like that :
this.console.getOut().print('\u0004');
this.console.getOut().flush();
this.console.getOut().close();

I don't understand how the bsh.Parser works and how i could let him know that there couldn't be any character because i close the window containing the Jconsole.

I suppose that in your case System.exit() was enough but please let me know if you have any idea.



robert lytle wrote
i'm trying to use JConsole, and i'm having two issues:
  1. hang/deadlock approximately 50% of the time
  2. output does not go to the console

I'm java-6 on linux. Here's my very simple class:  

public class Console2 extends javax.swing.JFrame {
    bsh.util.JConsole bconsole;
    bsh.Interpreter sh;
    public Console2() {

        bconsole = new bsh.util.JConsole();
        sh = new bsh.Interpreter(bconsole);
        new Thread(sh).start();

        this.setSize(600, 600);
        this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        this.getContentPane().add(bconsole);
    }
    public static void main(String args[]) {
        Console2 console = new Console2();
        console.setVisible(true);
    }
}
...
Reply | Threaded
Open this post in threaded view
|

Re: using JConsole - hangs and setOut issues

robert lytle
i'm glad the code was helpful

i'm not familiar with the OSGi model (took a quick look at wikip) so i'm just guessing on what
you're trying to do. but... this seemed a bit flakey to me too - i think i don't understand the
details of the treading well enough. what i finally found worked, but i'd tried many other things
that i thought should work first.

but you can have multiple interpretters at once - my guess is that you can just disconnect the
interpetter from the input/output and let it be gc'd. but it's just a guess

also, when i tried running the interpretter in a separate thread i was seeing deadlocks and the io
wasn't working right. if i get a chance i'll try running your code and see what i get.

seth


--- ecor6633 <[hidden email]> wrote:

>
> Thanks a lot for that example of using a Jconsole. I can now successfuly use
> my own console. The problem is how to stop the Interpreter Thread... ?
>
> I will have to use my Jconsole in an OSGi framework in the future so it's
> totally impossible to use System.exit(0);. I have to send an EOF so that the
> Thread can end its loop.
>
> Here is the code i used :
> console = new JConsole();
> interpreter = new Interpreter(console, namespace);
> interpreter.setExitOnEOF(false);
> interpreter.setShowResults(true);
> interpreteurThread = new Thread(interpreter);
> interpreteurThread.start();
>
> I already tried closing input or output streams, passing \u0004 like that :
> this.console.getOut().print('\u0004');
> this.console.getOut().flush();
> this.console.getOut().close();
>
> I don't understand how the bsh.Parser works and how i could let him know
> that there couldn't be any character because i close the window containing
> the Jconsole.
>
> I suppose that in your case System.exit() was enough but please let me know
> if you have any idea.
>
>
>
>
> robert lytle wrote:
> >
> > i'm trying to use JConsole, and i'm having two issues:
> >   1. hang/deadlock approximately 50% of the time
> >   2. output does not go to the console
> >
> > I'm java-6 on linux. Here's my very simple class:  
> >
> > public class Console2 extends javax.swing.JFrame {
> >     bsh.util.JConsole bconsole;
> >     bsh.Interpreter sh;
> >     public Console2() {
> >
> >         bconsole = new bsh.util.JConsole();
> >         sh = new bsh.Interpreter(bconsole);
> >         new Thread(sh).start();
> >
> >         this.setSize(600, 600);
> >        
> > this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
> >         this.getContentPane().add(bconsole);
> >     }
> >     public static void main(String args[]) {
> >         Console2 console = new Console2();
> >         console.setVisible(true);
> >     }
> > }
> > ...
> >
>
> --
> View this message in context:
> http://www.nabble.com/using-JConsole---hangs-and-setOut-issues-tp16643186p16834642.html
> Sent from the BeanShell - User mailing list archive at Nabble.com.
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> Don't miss this year's exciting event. There's still time to save $100.
> Use priority code J8TL2D2.
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>



      ____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: using JConsole - hangs and setOut issues

ecor6633
Well thanks,
My problem is the deadlocks you are talking about. I'm not really comfortable with threads so i tried running the interpreter on the same thread as swing but it freezed my window and prevent me closing it.
I dind't understand quite well the tip given there : http://www.beanshell.org/manual/jconsole.html

The OSGi context is not the real problem, it forces me to manage many threads and untill now i just placed a boolean like:
publiv void run(){
  while(running){...}
}
public void stop(){this.running=false;}
So if an event require me to stop a thread i just call a method that stop it.

So my question now would be does anybody can explain me this deadlock ?

If i run the interpreter on an other thread than swing is there any solution to stop this thread ?


robert lytle wrote
i'm glad the code was helpful

i'm not familiar with the OSGi model (took a quick look at wikip) so i'm just guessing on what
you're trying to do. but... this seemed a bit flakey to me too - i think i don't understand the
details of the treading well enough. what i finally found worked, but i'd tried many other things
that i thought should work first.

but you can have multiple interpretters at once - my guess is that you can just disconnect the
interpetter from the input/output and let it be gc'd. but it's just a guess

also, when i tried running the interpretter in a separate thread i was seeing deadlocks and the io
wasn't working right. if i get a chance i'll try running your code and see what i get.

seth