1. private 改成public2. exampe 大写 构造函数里面调用super()
3.private static int getCount() {  
return count;
}  static去掉4.getCount() = 0  改成 getCount() == 0 
5.加上out.flush(); out.cloas();6.d.length() 改d.length

解决方案 »

  1.   

    1. private 改成public
    只能声明为public,abstract,final的2.private static int getCount() {  
    return count;
    }  static去掉静态方法不能调用非静态变量
    3.getCount() = 0  改成 getCount() == 0 
    4.加上out.flush(); out.cloas();5.d.length() 改d.length
      

  2.   

    Servlet找错误:
    1、private class example extends HttpServlet{
      pbulic class example extends HttpServlet{2、int count;
       int count=0;3、private static int getCount(){ 
       private int getCount(){4、if(getCount() = 0 )
       if(getCount() == 0 )5、out.println( "length of the array d = " + d.length() );
       out.println( "length of the array d = " + d.length );线程那道还没教,不予回答,哈哈
      

  3.   

    第二题的错误大家说过的我就不说了,只是有一点,
    //To create default constructor
    public void example() {
            ++count;
    }
    这里的注释说的是创建默认构造函数,而且如果此方法是普通方法的话,在main函数里也没调用,所以这里应该是写的构造函数,构造函数没有返回值,方法名必须与类名一致,而且在默认构造函数里必须对类成员变量赋值。
      

  4.   

    第一题是这样吗public static void main(String[] args) throws Exception {
         SMTPReceiver sr = new SMTPReceiver();
         Thread worker = new Thread(sr);
         worker.start();
         // 暂停
         while(sr.m_IsWorking){
         worker.interrupt();
         Thread.sleep(1000);
         }
        
         // 恢复
         while(!sr.m_IsWorking){
         worker.interrupt();
         Thread.sleep(1000);
         }
        
         // 退出
         Field field = SMTPReceiver.class.getDeclaredField("m_stopApp");
         field.setAccessible(true);
         field.setBoolean(sr, true);
         field.setAccessible(false);
         System.out.println(sr.getStopFlag());
        
        
        }
      

  5.   

    public static void main(String[] args) throws Exception {
         SMTPReceiver sr = new SMTPReceiver();
         Thread worker = new Thread(sr);
         worker.start();
         // 暂停
         while(sr.m_IsWorking){
         worker.interrupt();
         Thread.sleep(1000);
         }
        
         // 恢复
         while(!sr.m_IsWorking){
         worker.interrupt();
         Thread.sleep(1000);
         }
        
         // 退出
         Field field = SMTPReceiver.class.getDeclaredField("m_stopApp");
         field.setAccessible(true);
         field.setBoolean(sr, true);
         field.setAccessible(false);   
        
        }
      

  6.   

    1、private class example extends HttpServlet{
      pbulic class example extends HttpServlet{2、exampe 类和构造方法大写3、private static int getCount(){ 
       private int getCount(){4、if(getCount() = 0 )
       if(getCount() == 0 )5、out.println( "length of the array d = " + d.length() );
       out.println( "length of the array d = " + d.length );
      

  7.   

    第二题
    怎么没人说把构造函数的void 去掉的??
      

  8.   

    楼上的,谁说没有,仔细看看我写的:
    第二题的错误大家说过的我就不说了,只是有一点,
    //To create default constructor
    public void example() {
            ++count;
    }
    这里的注释说的是创建默认构造函数,而且如果此方法是普通方法的话,在main函数里也没调用,所以这里应该是写的构造函数,构造函数没有返回值,方法名必须与类名一致,而且在默认构造函数里必须对类成员变量赋值。
      

  9.   

    import java.lang.reflect.Field;public class SMTPReceiver implements Runnable {
    public boolean m_IsWorking = true; // true为线程在执行状态,false为暂停 private boolean m_stopApp = false; // true表示线程状态live; false为dead public void run() {
    while (true) {
    if (this.m_stopApp)
    break; m_IsWorking = true;
    // 在此执行大数据量文件操作 try {
    Thread.sleep(1000);
    } catch (InterruptedException ie) {
    m_IsWorking = false; // 线程暂停
    try {
    while (true) {
    Thread.sleep(1000);
    }
    } catch (InterruptedException iie) {
    }
    }
    }
    } public static void main(String[] args) throws Exception {
    SMTPReceiver sr = new SMTPReceiver();
    Thread worker = new Thread(sr);
    worker.start();
    // ***************
    // 暂停线程
    // 先暂停后恢复线程
    // 退出线程
    // 重启线程
    // 暂停
    while (sr.m_IsWorking) {
    worker.interrupt();
    Thread.sleep(1000);
    } // 恢复
    while (!sr.m_IsWorking) {
    worker.interrupt();
    Thread.sleep(1000);
    } // 退出
    Field field = SMTPReceiver.class.getDeclaredField("m_stopApp");
    field.setAccessible(true);
    field.setBoolean(sr, true);
    field.setAccessible(false);
    // System.out.println(sr.getStopFlag());



    // 重启线程??? }
    }
      

  10.   

    线程的比较感兴趣,我没什么经验,参照上面的答案写的package org.chenliang.interview;import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.lang.reflect.Field;
    import java.util.Date;public class SMTPReceiver implements Runnable {
    public boolean m_IsWorking = true; // true为线程在执行状态,false为暂停
    private boolean m_stopApp = false; // true表示线程状态live; false为dead public void run() {
    System.out.println("Just start running at :" + new Date());
    while (true) {
    if (this.m_stopApp) {
    System.out.println("Receive exit order,about to exit.");
    break;
    } m_IsWorking = true;
    // 在此执行大数据量文件操作 try {
    // Simulate the file operations
    // System.out.println("Simulating working...");
    Thread.sleep(1000);
    } catch (InterruptedException ie) {
    // if interrupted when operating the big
    // amount of files wait until interrupted
    // to run again
    System.out.println("Receiving pause order,pauing.");
    m_IsWorking = false; // 线程暂停
    try {
    while (true) {
    Thread.sleep(200000);
    }
    } catch (InterruptedException iie) {
    System.out.println("Wake up from the paused state.");
    }
    }
    }
    } public static void main(String[] args) throws Exception {
    SMTPReceiver sr = new SMTPReceiver();
    Thread worker = new Thread(sr);
    worker.start();
    // ***************
    boolean shouldExit = false;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    while (!shouldExit) {
    System.out.print("Please input command 1/pause 2/stop 3/restart 4/wakeup 5/exit):");
    String commandString = br.readLine();
    int command = -1;
    try {
    command = Integer.parseInt(commandString);
    } catch (Exception e) {
    // e.printStackTrace();
    }
    switch (command) {
    case 1 :
    // pause
    if (sr.m_IsWorking) {
    worker.interrupt();
    }
    break;
    case 2 :
    // stop
    Field shouldStopField = SMTPReceiver.class.getDeclaredField("m_stopApp");
    shouldStopField.setBoolean(sr, true);
    while (worker.isAlive()) {
    System.out.println("Wait for the old worker to die.");
    }
    if (!sr.m_IsWorking) {
    worker.interrupt();
    }
    break;
    case 3 :
    // restart
    // stop
    shouldStopField = SMTPReceiver.class.getDeclaredField("m_stopApp");
    shouldStopField.setBoolean(sr, true);
    while (worker.isAlive()) {
    System.out.println("Wait for the old worker to die.");
    }
    shouldStopField.setBoolean(sr, false);
    // start
    worker = new Thread(sr);
    worker.start();
    break;
    case 4 :
    // wakeup
    if (!sr.m_IsWorking) {
    worker.interrupt();
    }
    break;
    case 5 :
    shouldExit = true;
    break;
    default :
    System.out.println();
    System.out.println("Invalid command.");
    }
    } }
    }
      

  11.   

    没明白重启线程什么意思
    先停止了再start?
    还是暂停在恢复叫重启
      

  12.   

    请登陆 http://blog.csdn.net/mqboss/ 上面有对java面试问题的专门的整理和解答