当前位置:首页 » 软件开发
开发技术指南» 文章正文
    引言: Have you ever wondered why
 

 

 ·j2me tutorial, part 1: creating midlets    »显示摘要«
    摘要:java 2 micro edition (j2me) combines a resource-constrained jvm and a set of java apis for developing applications for mobile devices. this article is the first in a series. this time, after a qui......
 ·revenge of the old fogeys? @ jdj    »显示摘要«
    摘要:(august 26, 2002) - for years, the badge of honor for a software engineer was the ability to write fast code that occupied a small amount of memory. in the days when 640k of ram was a luxury and 10 mh......


Beware the Daemons @ JDJ
上一页   ...risk. first, you can explicitly specify a thread to be a daemon thread by calling setdaemon(true) on a thread object. note that the setdaemon() method must be called before the threads start() method is invoked, as the following snippet shows:

1: thread t = new thread() {

3: system.out.println("im a 【程序编程相关:关于runtime exception和

2: public void run() { 【推荐阅读:我对构架MVC的理解

4: } 【扩展信息:JVM结构基础(一)

man of wealth and taste...");

5: };

6:

7: t.setdaemon(true);

8: t.start();

the second technique for creating a daemon thread is based on an often overlooked feature of javas threading behavior. if a thread creates a new thread and doesnt call setdaemon() on the new thread before its started, the new thread will inherit the "daemon-status" of the creating thread. for example, unless setdaemon(false) is called, all threads created by daemon threads will also be daemon threads; likewise, unless setdeamon(true) is called, all threads created by user threads will be user threads.

the program in listing 2 illustrates this behavior. the program creates a thread, t1, whose only purpose in life is to create another thread, t2, whose destiny is to print a greeting, "pleased to meet you," for all eternity. if you run this code youll see that even though the main thread ends, t2 goes on forever, printing its tempting message. this behavior is due to the fact that t2 inherited its user
...   下一页

 ·java tech: language lessons    »显示摘要«
    摘要:i first encountered java in 1995. that language soon became my favorite because of its elegance, its interesting language features (e.g., interfaces, garbage collector, and threads), and its simila......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE