你在这个程序中到底想干什么?
你的wait();中没有用synchronized先取得this的lock
而且你只要你wait了,根本就不会运行到notify中。所以你的代码应该是有问题的
(不要以为一个notify就会唤醒所有的线程,它只会唤醒自己而已)

解决方案 »

  1.   

    是hehe 
    异常里的输出结果阿.
      

  2.   

    agree with chdw, but one point I have to clear that notify() is not to wake yourself, it's not sure which thread is waked up when you call notify().
      

  3.   

    呵呵,诸位不要瞎猜了,一个简单的数组越界居然没人能看得出来。
    id==2
    turn%3
    i<3
    就全搞定了,看来这里实在没什么高手可言了。
      

  4.   

    佩服佩服,看看下面程序有什么问题!
    package com.dt.dps.sbgl.codebase;
    /**
    *
    *                -  File Name : [FILE_NAME][FILE_EXTENSION]  - 
    *
    * ==========================================================================
    *
    * - Description
    *
    *    This file has no description yet.
    *
    * - What's new !
    *
    *    No update valid.
    *
    * ==========================================================================
    *
    *
    * - File Author       :    Wafer. W.  &pound;¨&Icirc;&ordm; ·&aelig;&pound;&copy;
    *
    * - Last Modification :    [DATE_TEXT]
    *
    * - Current Version   :    Ver 1.0
    *  
    * - Copyright (C)2002 Wafer All rights reserved.
    *
    * - Licensed under GNU LGPL (www.gnu.org)
    *
    * ==========================================================================
    * The Wafer Software License, Version 1.1
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
    *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in 
    *    the documentation and/or other materials provided with the
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution,
    *    if any, must include the following acknowledgment:
    *       "This product includes software developed by wafer (&Icirc;&ordm;·&aelig;&pound;&copy;."
    *    Alternately, this acknowledgment may appear in the software itself,
    *    if and wherever such third-party acknowledgments normally appear.
    *
    */import com.dt.dps.sbgl.jscs.*;
    import com.dt.dps.sbgl.util.*;
    import com.dt.dps.sbgl.iterator.*;
    import java.sql.*;public class SbVoltageGrade {  
      private String voltageBm;
      private String voltageMc;
      private Double sortField;
      private boolean isModfy=false;
      private LogWriter logwriter;
      private static final String INSERT =
            "INSERT INTO sb_user.sb_voltage_grade_table_m VALUES (?,?,?)";
      private static final String UPDATE =
            "UPDATE sb_user.sb_voltage_grade_table_m SET VOLTAGE_MC=? WHERE VOLTAGE_BM=?,SORT_FIELD=?";
      private static final String DELETE =
            "DELETE FROM sb_user.sb_voltage_grade_table_m WHERE VOLTAGE_BM=?";
      private static final String GET_BYKEY =
            "SELECT VOLTAGE_MC,SORT_FIELD FROM sb_user.sb_voltage_grade_table_m WHERE VOLTAGE_BM=? ";
      
      /** DATABASE QUERIES **/
        private static final String GET_ALL =
            "SELECT VOLTAGE_BM FROM sb_user.sb_voltage_grade_table_m ";
            
      public SbVoltageGrade(String voltageBm) throws SbNotFoudException {
       this.logwriter=new LogWriter(this);
       PreparedStatement pstmt=null;
        java.sql.Connection conn=null;
        java.sql.ResultSet rs=null;    
        try{ conn=this.getConnection();
             pstmt=conn.prepareStatement(GET_BYKEY);
             pstmt.setString(1,voltageBm);         
             rs=pstmt.executeQuery();
             if (rs.next()) {
              this.voltageBm=voltageBm;
              this.voltageMc=rs.getString("VOLTAGE_MC");
                this.sortField=new Double(rs.getDouble("SORT_FIELD"));          
             }else{
               this.logwriter.log("not find this item:"+voltageBm+":from sb_user.sb_voltage_grade_table_m",
                 this.logwriter.INFO);
               throw new SbNotFoudException("&Ocirc;&Uacute;&micro;&ccedil;&Ntilde;&sup1;&micro;&Egrave;&frac14;&para;±à&Acirc;&euml;±í&Atilde;&raquo;&Oacute;&ETH;&Otilde;&Ograve;&micro;&frac12;&cedil;&Atilde;&Iuml;&icirc;&pound;&ordm;"+voltageBm);
             }         
        }catch(SQLException e){
           this.logwriter.log("error when select by voltageBm from sb_user.sb_voltage_grade_table_m"+e.getMessage(),
             this.logwriter.ERROR);
        }finally{
           rs=null;
           //&Ecirc;&Iacute;·&Aring;&Ecirc;&yacute;&frac34;&Yacute;&iquest;&acirc;&Aacute;&not;&frac12;&Oacute;
           this.freeConnection(pstmt,conn);
        }
        
      }   
      public SbVoltageGrade(String voltageBm, String voltageMc, Double sortField) throws
        SbAlreadyExistException {
        this.voltageBm = voltageBm;
        this.voltageMc = voltageMc;
        this.sortField = sortField;
        insert();
      }
     /*
      public SbVoltageGrade(String voltageBm,String voltageMc) {
        SbVoltageGrade(voltageBm,voltageMc, null);
      } 
      */ 
      public String getVoltageBm() {
        return voltageBm;
      }
      public String getVoltageMc() {
        return voltageMc;
      }
      public void setVoltageMc(String voltageMc) {
        this.voltageMc = voltageMc;
        this.isModfy=true;
      }
      public Double getSortField() {
        return sortField;
      }
      public void setSortField(Double sortField) {
        this.sortField = sortField;
        this.isModfy=true;
      }
      public static EMIterator findAll() {
        return new SbVoltageGradeIterator(GET_ALL);
      }
        
      public void commit() {
       if (this.isModfy) {
         PreparedStatement pstmt=null;
          java.sql.Connection conn=null;
          try{
              conn=this.getConnection();          pstmt=conn.prepareStatement(UPDATE);          
              pstmt.setString(1,this.voltageMc);
              pstmt.setDouble(2,this.sortField.doubleValue());
              pstmt.setString(3,this.voltageBm);          
              pstmt.executeUpdate();
          }catch(Exception e){
            this.logwriter.log("error when update data of sb_user.sb_voltage_grade_table_m:"+e.getMessage(),
              this.logwriter.ERROR);
          }finally{
            //&Ecirc;&Iacute;·&Aring;&Ecirc;&yacute;&frac34;&Yacute;&iquest;&acirc;&Aacute;&not;&frac12;&Oacute;
            this.freeConnection(pstmt,conn);
          }  
       }
      }  
      
      public void delete() {
        PreparedStatement pstmt=null;
        java.sql.Connection conn=null;
        try{ conn=this.getConnection();
             pstmt=conn.prepareStatement(DELETE);
             pstmt.setString(1,this.voltageBm);         
             pstmt.executeUpdate();
        }catch(Exception e){
           logwriter.log("error when insert data into sb_user.sb_voltage_grade_table_m",
             logwriter.ERROR);
        }finally{
           //&Ecirc;&Iacute;·&Aring;&Ecirc;&yacute;&frac34;&Yacute;&iquest;&acirc;&Aacute;&not;&frac12;&Oacute;
           this.freeConnection(pstmt,conn);
        }
      } 
      
      private void insert() throws SbAlreadyExistException {
        PreparedStatement pstmt=null;
        java.sql.Connection conn=null;
        try{ conn=this.getConnection();
             pstmt=conn.prepareStatement(INSERT);
             pstmt.setString(1,this.voltageBm);
             pstmt.setString(2,this.voltageMc);
             pstmt.setDouble(3,this.sortField.doubleValue());
             pstmt.executeUpdate();
        }catch(Exception e){
           this.logwriter.log("error when insert data into sb_user.sb_voltage_grade_table_m:"+e.getMessage(),
             this.logwriter.ERROR);
        }finally{
           //&Ecirc;&Iacute;·&Aring;&Ecirc;&yacute;&frac34;&Yacute;&iquest;&acirc;&Aacute;&not;&frac12;&Oacute;
           this.freeConnection(pstmt,conn);
        }  
      }
      
      private Connection getConnection() {    
        try {
          ConnectionDataBase connectionDataBase=new ConnectionDataBase();
          return connectionDataBase.getConnection();
        }catch (Exception e){
          logwriter.log("this error happen when get the connect from ConnectionDataBase:"+e.getMessage(),
            logwriter.ERROR);
        }
        return null;
      }
      
      private void freeConnection(PreparedStatement pstmt,java.sql.Connection conn)
      {
       try{
             pstmt.close();
            }
         catch(Exception e){
           logwriter.log("error happen when close the pstmt",
            logwriter.ERROR);
         }
         try
            {
             conn.close();
            }
         catch(Exception e) {
          logwriter.log("error happen when close the dbconnection",
            logwriter.ERROR);
          }
      }
    }
      

  5.   

    呵呵,wafer_w,这两天我没上网,你至于得意成这样吗?DBC!