这是java类
1.抛出太多连接错误后几秒钟? 如何解决这个问题
2.org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions 错误:数据源拒绝建立连接,来自服务器的消息:“连接太多” org.hibernate.exception.JDBCConnectionException:无法打开连接
3.com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:数据源拒绝建立连接,来自服务器的消息:“连接太多”
package MVC;
import POJOs.TheaterBookingSeatDetAss;
import POJOs.TheaterBookingSeatDetils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import org.hibernate.Criteria;
import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
public class thread_servlet extends HttpServlet {
public void Search_Timeout_Details() throws Exception {
//Create Main While
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
Session s = Connection.connector.getSessionFactory().openSession();enter code here
Criteria c = s.createCriteria(POJOs.TheaterBookingSeatDetils.class);
c.add(Restrictions.eq("timeoutState", "1"));
c.add(Restrictions.eq("state", "1"));
List<POJOs.TheaterBookingSeatDetils> ptd = c.list();
if (ptd.isEmpty()) {
System.out.println("no");
} else {
System.out.println("yes");
for (TheaterBookingSeatDetils tnsd : ptd) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdft = new SimpleDateFormat("HH:mm:s");
Calendar now = Calendar.getInstance();
Date sd = now.getTime();
String current_date = sdf.format(sd);
String current_time = sdft.format(sd);
try {
Date date1 = sdf.parse(current_date);
Date date2 = sdf.parse(tnsd.getTimeoutDate());
Date date3 = sdft.parse(tnsd.getTimeoutTime());
Date date4 = sdft.parse(current_time);
if (date1.equals(date2)) {
if (date4.equals(date3) | date3.before(date4)) {
int id = tnsd.getIdtheaterBookingSeatDetils();
POJOs.TheaterBookingSeatDetils ptb = (POJOs.TheaterBookingSeatDetils) s.load(POJOs.TheaterBookingSeatDetils.class, id);
System.out.println(ptb.getIdtheaterBookingSeatDetils());
//db eken remove wenna code karanna one
//
Criteria cc = s.createCriteria(POJOs.TheaterBookingSeatDetAss.class);
List<POJOs.TheaterBookingSeatDetAss> ll = cc.add(Restrictions.eq("theaterBookingSeatDetils", ptb)).list();
if (ll.isEmpty()) {
} else {
for (TheaterBookingSeatDetAss ptas : ll) {
s.delete(s.load(POJOs.TheaterBookingSeatDetAss.class, ptas.getIdtheaterBookingSeatDetAss()));
}
}
s.delete(ptb);
s.beginTransaction().commit();
System.out.println("time Deleted");
}
} else if (date2.before(date1)) {
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
s.clear();
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();
}
public static void main(String[] args) throws Exception {
thread_servlet ts = new thread_servlet();
ts.Search_Timeout_Details();
}
}