import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
public class Hello { public Hello() {
// TODO Auto-generated constructor stub
} /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new Hello().test();
}
public void test()
{
CountDownLatch latch =new CountDownLatch(1);
ThreaGroups group = new ThreaGroups();
Thread group_t = new Thread(group);
group_t.setDaemon(true);
group_t.start();
Test t1 = new Test(latch);
Thread g1 = new Thread(t1);
g1.setDaemon(true);
g1.start();
group.addThread(g1);
try {
if(!latch.await(10, TimeUnit.SECONDS))
{
System.out.println("超时结束");
g1.interrupt();
g1.stop();
g1 = null;
}else
{
System.out.println("正常结束");
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int i=0;i<100;i++)
{
try{
Thread.sleep(5000);
}catch(Exception e){}
}
}
class Test implements Runnable
{
CountDownLatch latch = null;
public Test(CountDownLatch latch){
this.latch = latch;
}
public void run()
{
for(int i=0;i<100;i++)
{
try{
System.out.println(Thread.currentThread().getName()+":" + Thread.currentThread().getState());
Thread.sleep(1000);
}catch(Exception e)
{
System.out.println(e.getMessage());
}
}
latch.countDown();
}
}
}class ThreaGroups implements Runnable
{
private List<Thread> list = new ArrayList<Thread>();
public boolean addThread(Thread t)
{
return list.add(t);
}
public void run()
{
Thread t = null;
while(true)
{
try{
for(int i=0;i<list.size();i++)
{
t = list.get(i);
if(t != null)
{
System.out.println("打印线程状态:" + t.getName() + ":" + t.getState());
}
}
Thread.sleep(2000);
}catch(Exception e)
{
}
}
}
}
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
public class Hello { public Hello() {
// TODO Auto-generated constructor stub
} /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new Hello().test();
}
public void test()
{
CountDownLatch latch =new CountDownLatch(1);
ThreaGroups group = new ThreaGroups();
Thread group_t = new Thread(group);
group_t.setDaemon(true);
group_t.start();
Test t1 = new Test(latch);
Thread g1 = new Thread(t1);
g1.setDaemon(true);
g1.start();
group.addThread(g1);
try {
if(!latch.await(10, TimeUnit.SECONDS))
{
System.out.println("超时结束");
g1.interrupt();
g1.stop();
g1 = null;
}else
{
System.out.println("正常结束");
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int i=0;i<100;i++)
{
try{
Thread.sleep(5000);
}catch(Exception e){}
}
}
class Test implements Runnable
{
CountDownLatch latch = null;
public Test(CountDownLatch latch){
this.latch = latch;
}
public void run()
{
for(int i=0;i<100;i++)
{
try{
System.out.println(Thread.currentThread().getName()+":" + Thread.currentThread().getState());
Thread.sleep(1000);
}catch(Exception e)
{
System.out.println(e.getMessage());
}
}
latch.countDown();
}
}
}class ThreaGroups implements Runnable
{
private List<Thread> list = new ArrayList<Thread>();
public boolean addThread(Thread t)
{
return list.add(t);
}
public void run()
{
Thread t = null;
while(true)
{
try{
for(int i=0;i<list.size();i++)
{
t = list.get(i);
if(t != null)
{
System.out.println("打印线程状态:" + t.getName() + ":" + t.getState());
}
}
Thread.sleep(2000);
}catch(Exception e)
{
}
}
}
}
解决方案 »
- java小游戏合集(附带源代码)
- 怎么在一JFrame中画图,不覆盖原有东西
- Java输入字符到文件中时空格后的部分不能输入
- 求助,java程序 如何通过读取xml文件来对软件重新配置
- 在线急等简单问题
- 郁闷!在WinXP SP2装了 JRE 5.0 后,IE就说啥也起不来了,发生了“致命错误”……
- 急!一个狂简单的问题,在线等
- 有无适用于java web程序的远程管理工具?
- 怎么在JAVA类中调用IE打开PDF文件?
- 关于JTextArea的问题
- 真是奇怪了,tablemodellistener从来都没有生效过,不知道怎么了??
- 求“01-09年中国移动短信平台业务量增长率走势”免费LINK
package com.weilei.ms;import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;public class Hello { public Hello() {
// TODO Auto-generated constructor stub } /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new Hello().test();
} public void test() {
CountDownLatch latch = new CountDownLatch(1);
ThreaGroups group = new ThreaGroups();
Thread group_t = new Thread(group);
group_t.setDaemon(true);
group_t.start();
Test t1 = new Test(latch);
Thread g1 = new Thread(t1);
g1.setDaemon(true);
g1.start();
group.addThread(g1);
try {
if (!latch.await(10, TimeUnit.SECONDS)) {
System.out.println("超时结束");
g1.interrupt();
g1.stop();
g1 = null;
} else {
System.out.println("正常结束");
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} for (int i = 0; i < 100; i++) {
try {
Thread.sleep(5000);
} catch (Exception e) {
}
}
} class Test implements Runnable {
CountDownLatch latch = null; public Test(CountDownLatch latch) {
this.latch = latch;
} public void run() {
for (int i = 0; i < 100; i++) {
try {
System.out.println(Thread.currentThread().getName() + ":"
+ Thread.currentThread().getState());
Thread.sleep(1000);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
latch.countDown();
}
}}class ThreaGroups implements Runnable {
private List<Thread> list = new ArrayList<Thread>(); public boolean addThread(Thread t) {
return list.add(t);
} public void run() {
Thread t = null;
while (true) {
try {
for (int i = 0; i < list.size(); i++) {
t = list.get(i);
if (t != null) {
System.out.println("打印线程状态:" + t.getName() + ":"
+ t.getState());
}
}
Thread.sleep(2000);
} catch (Exception e) {
}
}
}
}
Java Learning Path(五)资源篇 1、 http://java.sun.com/ (英文)
Sun的Java网站,是一个应该经常去看的地方。不用多说。 2、http://www-900.ibm.com/developerWorks/cn/
IBM的developerWorks网站,英语好的直接去英文主站点看。这里不但是一个极好的面向对象的分析设计网站,也是Web Services,Java,Linux极好的网站。强烈推荐!!! 3、http://www.javaworld.com/ (英文)
关于Java很多新技术的讨论和新闻。想多了解Java的方方面面的应用,这里比较好。 4、http://dev2dev.bea.com.cn/index.jsp
BEA的开发者园地,BEA作为最重要的App Server厂商,有很多独到的技术,在Weblogic上做开发的朋友不容错过。 5、http://www.huihoo.com/
灰狐动力网站,一个专业的中间件网站,虽然不是专业的Java网站,但是在J2EE企业应用技术方面有深厚的造诣。 6、http://www.theserverside.com/home/ (英文)
TheServerSide是一个著名的专门面向Java Server端应用的网站。 7、http://www.javaresearch.org/
Java研究组织,有很多优秀的Java方面的文章和教程,特别是在JDO方面的文章比较丰富。 8、http://www.cnjsp.org/
JSP技术网站,有相当多的Java方面的文章和资源。 9、http://www.jdon.com/
Jdon论坛,是一个个人性质的中文J2EE专业技术论坛,在众多的Java的中文论坛中,Jdon一个是技术含量非常高,帖子质量非常好的论坛。 10、http://sourceforge.net/
SourgeForge是一个开放源代码软件的大本营,其中也有非常非常丰富的Java的开放源代码的著名的软件。
// TODO Auto-generated method stub
Properties properties = new Properties();
properties.put("org.omg.CORBA.ORBClass", "com.ibm.CORBA.iiop.ORB");
properties.put(Context.PROVIDER_URL, "iiop://localhost:2809");
properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");properties.setProperty(Context.SECURITY_PRINCIPAL, "guo");
properties.setProperty(Context.SECURITY_CREDENTIALS, "guo");try{
Context context = new InitialContext(properties);
itso.bank.SecurityEJB security = (itso.bank.SecurityEJB)context.lookup("ejb/TestEJB/TestEJB.jar/SecurityEJBBean#itso.bank.SecurityEJB");
System.out.println(security.echo("XXX"));
}
}还有2个props文件
users.props# Format:
# name:passwd:uid:gids:display name
# where name = userId/userName of the user
# passwd = password of the user
# uid = uniqueId of the user
# gid = groupIds of the groups that the user belongs to
# display name = (optional) display name for the user
admin:admin:0:0:Administrator
guo:guo:1::
visitor:visitor:2::
jacek:password:3::
groups.props# Format:
# name:gid:users:display name
# where name = groupId of the group
# gid = uniqueId of the group
# users = list of all the userIds that the group contains
# display name = (optional) display name for the group
administrator:0:admin:Administrative group
user:1:guo:1
PLINK.EXE
PSCP.EXE
PSFTP.EXE
PUTTY.CHM
PUTTY.EXE
PUTTYGEN.EXE
PUTTY.CNT
winscp
SecureCRT622-x86.rar
beyondcompare
PLINK.EXE
PSCP.EXE
PSFTP.EXE
PUTTY.CHM
PUTTY.EXE
PUTTYGEN.EXE
PUTTY.CNT
winscp
SecureCRT622-x86.rar
beyondcompare