免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1800 | 回复: 3
打印 上一主题 下一主题

在做多线程时的一个例提的错误码,请帮忙!!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-02-06 16:42 |只看该作者 |倒序浏览
程序如下:
import java.io.*;
public class ThreadInfo{
        static PrintWriter out=new PrintWriter(System.out,true);
        public static void main(String[] args){
                Thread[] thread=new Thread[4];
                ThreadGroup group = new ThreadGroup("MyThreadGroup");
                if(args.lenght>0){
                        Thread thread=Thread.currentThread();
                        thread.setName(args[0]);
                }
                for (int i=0;i<4;i++){
                        thread[i]=new Thread(group,"MyThread#"+i);
                        ThreadInfo.printAllThreadInfo();
                }
                public static void printAllThreadInfo(){
                        ThreadGroup parent,root;
                        root = parent = Thread.currentThread().getThreadGroup();
                        while((parent=parent.getParent())!=null)
                                root=parent;
                        out.println();
                        printThreadGroupInfo("",root);
                }
                public static void printThreadGroupInfo(String indent,ThreadGroup group){
                        final int SAFRTY = 5;
                        if(group==null)
                                return;
                        out.println(indent+" THREAD GROUP: "+group.grtName()
                        +" ;Max Priority: "+ group.getMaxPriority()+
                        (group.isDaemon()?"[Daemon]":""));
                        int numThreads=group.activeCount();
                        Thread threads[]=new Thread[numThreads+SAFETY];
                        numThreads=group.enumerate(threads,false);
                        for (int i = 0;i<numThreads;i++)
                                printThreadInfo(indent+"",threads[i]);
                        int numGroups=group.activeGroupCount();
                        ThreadGroup groups[]=new ThreadGroup[numGroups+SAFETY];
                        numGroups=group.enumerate(groups,false);
                        for(int i=0;i<numGroups;i++)
                                printThreadGroupInfo(indent+"",groups[i]);
                                {
                                        public static void printThreadInfo(String indent,Thread thread){
                                                if(thread==null)
                                                        return;
                                                out.println(indent+"THREAD:"+thread.getName()+
                                                (thread.isDaemon()?"[Daemon]":"")+
                                                (thread.isAlive()?"[Alive]":"[NotAlive]")+
                                                ((Thread.currentThread()==thread)?"<==current":""));
                                       }
                                }
                }
        }
}


错误提示:
E:\javaLesson>javac ThreadInfo.java
ThreadInfo.java:15: illegal start of expression
                public static void printAllThreadInfo(){
                ^
ThreadInfo.java:46: ';' expected
        }
        ^
2 errors

我找了一个下午好像没有错,但是总是这样的提示,帮帮忙!!谢谢

论坛徽章:
0
2 [报告]
发表于 2007-02-06 16:59 |只看该作者
上面程序找到一些错误,改了后的为:
import java.io.*;
public class ThreadInfo{
        static PrintWriter out=new PrintWriter(System.out,true);
        public static void main(String[] args){
                Thread[] thread=new Thread[4];
                ThreadGroup group = new ThreadGroup("MyThreadGroup");
                if(args.length>0){
                        thread=Thread.currentThread();
                        thread.setName(args[0]);
                }
                for (int i=0;i<4;i++){
                        thread[i]=new Thread(group,"MyThread#"+i);
                        ThreadInfo.printAllThreadInfo();
                }
                public static void printAllThreadInfo(){
                        ThreadGroup parent,root;
                        root = parent = Thread.currentThread().getThreadGroup();
                        while((parent=parent.getParent())!=null)
                                root=parent;
                        out.println();
                        printThreadGroupInfo("",root);
                }
                public static void printThreadGroupInfo(String indent,ThreadGroup group){
                        final int SAFRTY = 5;
                        if(group==null)
                                return;
                        out.println(indent+" THREAD GROUP: "+group.getName()
                        +" ;Max Priority: "+ group.getMaxPriority()+
                        (group.isDaemon()?"[Daemon]":""));
                        int numThreads=group.activeCount();
                        Thread threads[]=new Thread[numThreads+SAFRTY];
                        numThreads=group.enumerate(threads,false);
                        for (int i = 0;i<numThreads;i++)
                                printThreadInfo(indent+"",threads[i]);
                        int numGroups=group.activeGroupCount();
                        ThreadGroup groups[]=new ThreadGroup[numGroups+SAFRTY];
                        numGroups=group.enumerate(groups,false);
                        for(int i=0;i<numGroups;i++)
                                printThreadGroupInfo(indent+"",groups[i]);
                                {
                                        public static void printThreadInfo(String indent,Thread thread){
                                                if(thread==null)
                                                        return;
                                                out.println(indent+"THREAD:"+thread.getName()+
                                                (thread.isDaemon()?"[Daemon]":"")+
                                                (thread.isAlive()?"[Alive]":"[NotAlive]")+
                                                ((Thread.currentThread()==thread)?"<==current":""));
                                       }
                                }
                }
        }
}
但是提示的错误还是一样的

论坛徽章:
0
3 [报告]
发表于 2007-02-06 20:01 |只看该作者
java还没有强到可以函数嵌套

论坛徽章:
0
4 [报告]
发表于 2007-02-07 13:28 |只看该作者
哈哈,我就看的很郁闷,那里的那么多定义函数,而且还是定义在函数体内的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP