你在这个程序中到底想干什么?
你的wait();中没有用synchronized先取得this的lock
而且你只要你wait了,根本就不会运行到notify中。所以你的代码应该是有问题的
(不要以为一个notify就会唤醒所有的线程,它只会唤醒自己而已)
你的wait();中没有用synchronized先取得this的lock
而且你只要你wait了,根本就不会运行到notify中。所以你的代码应该是有问题的
(不要以为一个notify就会唤醒所有的线程,它只会唤醒自己而已)
解决方案 »
- C#转Java,long转int的数据溢出但程序不报错问题 谢谢
- 在使用jsp做登录程序遇到的问题,老是找不出原因,望大家来指点下,谢谢
- 请问,在java中做一个一般的画笔小程序用什么包?
- 再问如何使就JFrame最大化?
- java调用ocx异常问题
- 关于java 中线程的问题!
- 关于JAVA开发数据库应用地问题
- win2K+tomcat4.0+jdk1.4的配置问题!
- tomcat6 绿色版 详细配置方法
- 初学者问个基础问题 见笑
- 最复杂的循环啊~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!
- 问一个163.com的聊天室和我本地JAVA出现矛盾的问题。。
异常里的输出结果阿.
id==2
turn%3
i<3
就全搞定了,看来这里实在没什么高手可言了。
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. £¨Îº ·æ£©
*
* - 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 (κ·æ£©."
* 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("ÔÚµçѹµÈ¼¶±àÂë±íûÓÐÕÒµ½¸ÃÏ"+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;
//ÊÍ·ÅÊý¾Ý¿âÁ¬½Ó
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{
//ÊÍ·ÅÊý¾Ý¿âÁ¬½Ó
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{
//ÊÍ·ÅÊý¾Ý¿âÁ¬½Ó
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{
//ÊÍ·ÅÊý¾Ý¿âÁ¬½Ó
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);
}
}
}