Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2008

Tip: Looking for answers? Try searching our database.

Higher Volume?

Thread view: 
JB - 03 Apr 2008 05:09 GMT
This does not seem to be a very high volume newsgroup.  Could someone
point me towards another resource where java newbs can get questions
answered in a timely fashion?
Signature

Still Playing NWN1?  Like retro-gaming?  Try my (free, of course) PW:
http://games.groups.yahoo.com/group/LotV

Christian Williamson - 03 Apr 2008 10:09 GMT
> This does not seem to be a very high volume newsgroup.  Could someone
> point me towards another resource where java newbs can get questions
> answered in a timely fashion?

What are you saying? Java is losing mindshare? ;-> Ask away....
JB - 03 Apr 2008 16:30 GMT
> What are you saying? Java is losing mindshare? ;-> Ask away....

OK!

Sample code follows.  I *just* started, this is like my second program
after hello world.  I'm trying to write a command line utility that
starts, and then every once in awhile does "something", so I'm using a
thread.  In the code sample below as is, the program starts, prints it's
intial message, and then stops.  I figured that the main program was
terminating and it's new thread with it.  So I added the line:

while (true) {}

in place of the comment "// iloop here"(*) to intentionally create an
infinite loop, so  that the program would only terminate with a CTRL-C
or similar.  This worked as far as the program not terminating, but I
still never see anything from the new thread.  Thanks for any advice you
can give to the newb.

package nwserverlogmonitor1;

public class Main {

    public static void main(String[] args) {
        System.out.println("nwServerLogMonitor Started");
        Thread t = new Thread();
        t.start();

        // iloop here
    }

public void run() {
    try {
        while (true) {
            System.out.println("I did something");
            Thread.sleep(5000);
        }
    }
    catch (InterruptedException ie) {}
    }
}

(*) how clever, a double entendre.  "iloop": "I Loop"  or "infinte
loop".  Either, both?  A mystery for the ages to all but the author

Signature

Still Playing NWN1?  Like retro-gaming?  Try my (free, of course) PW:
http://games.groups.yahoo.com/group/LotV

Ian Shef - 03 Apr 2008 20:15 GMT
I could fix this for you, but I am not sure you want that.  Instead, here
are some hints at what went wrong.

JB <jtbmax@columbus.rr.com> wrote in news:47f4f823$0$17343
$4c368faf@roadrunner.com:

<snip>

> This worked as far as the program not terminating, but I
> still never see anything from the new thread.  Thanks for any advice you
[quoted text clipped - 3 lines]
>
> public class Main {

NOTE:  Main extends Object (by default), not Thread.  Also, to nitpick a
little, not a good choice of name.

>      public static void main(String[] args) {
>          System.out.println("nwServerLogMonitor Started");
>          Thread t = new Thread();

NOTE:  t is a Thread with an empty run() method.

>          t.start();

Nice, but t has an empty run() method that immediately returns (ends the
Thread).

>          // iloop here
>      }

NOTE:  This run() method never gets called or started.

> public void run() {
>      try {
[quoted text clipped - 3 lines]
>          }
>      }

OUCH!  The try-catch should print something useful, and/or should be inside
the infinite loop.

>      catch (InterruptedException ie) {}
>      }
> }

<snip>
Christian Williamson - 04 Apr 2008 08:04 GMT
>> What are you saying? Java is losing mindshare? ;-> Ask away....
>
> OK!
>
> Sample code follows.  I *just* started, this is like my second program
> after hello world.  

Great! Keep coding. It's good for the brain.

The code below works. I've added three things:
o indicated that Main implements Runnable,
o created a new instance of Main, and
o gave the new instance as an argument to the Thread constructor.

public class Main implements Runnable {
   public static void main(String[] args) {
       System.out.println("nwServerLogMonitor Started");
    Main m = new Main();
       Thread t = new Thread(m);
       t.start();

    while ( true ) {}
       // iloop here
   }
   public void run() {
   try {
       while (true) {
           System.out.println("I did something");
           Thread.sleep(5000);
       }
   }
   catch (InterruptedException ie) {}
   }
}

> I'm trying to write a command line utility that
> starts, and then every once in awhile does "something", so I'm using a
[quoted text clipped - 35 lines]
> (*) how clever, a double entendre.  "iloop": "I Loop"  or "infinte
> loop".  Either, both?  A mystery for the ages to all but the author
Robert Larsen - 04 Apr 2008 08:29 GMT
>     while ( true ) {}

This will probably make your CPU go crazy so do this instead:
while (true) {
 try {
   Thread.sleep(10000000000);
 } catch (Exception e) {
 }
}

...that way the CPU won't be held busy doing nothing.
Christian Williamson - 04 Apr 2008 09:36 GMT
>>     while ( true ) {}
>
[quoted text clipped - 7 lines]
>
> ...that way the CPU won't be held busy doing nothing.

Yep, good catch.
Christian Williamson - 03 Apr 2008 10:13 GMT
> This does not seem to be a very high volume newsgroup.  Could someone
> point me towards another resource where java newbs can get questions
> answered in a timely fashion?

If you're looking for great examples for Java, check out these sites:

http://java.sun.com/docs/books/tutorial/uiswing/examples/components/index.html#C
omboBoxDemo2

http://www.java2s.com/
http://mindprod.com/jgloss/jgloss.html
http://www.onjava.com/
http://www.javaranch.com/

Also, I just picked up "Java Phrasebook." It's a compact book for quick,
basic Java code.
http://www.amazon.com/Phrasebook-Developers-Library-Timothy-Fisher/dp/0672329077
/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1207213967&sr=8-1

Joshua Cranmer - 03 Apr 2008 22:29 GMT
> This does not seem to be a very high volume newsgroup.  Could someone
> point me towards another resource where java newbs can get questions
> answered in a timely fashion?

news:comp.lang.java.programmer
news:comp.lang.java.help
news:comp.lang.java.gui
news:comp.lang.java.database

etc.

Signature

Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.