Date: Wed, 14 Aug 2002 03:52:05 -0700 From: Bill Huey (Hui) <billh@gnuppy.monkey.org> To: Huang wen hui <hwh@mail.gddsn.org.cn> Cc: java <java@FreeBSD.ORG>, "Bill Huey (Hui)" <billh@gnuppy.monkey.org> Subject: Re: Hotspot vm is extremely slower than nojit vm on current ? Message-ID: <20020814105205.GA5605@gnuppy.monkey.org> In-Reply-To: <3D59C6A4.5020708@mail.gddsn.org.cn> References: <3D59C6A4.5020708@mail.gddsn.org.cn>
index | next in thread | previous in thread | raw e-mail
On Wed, Aug 14, 2002 at 10:55:32AM +0800, Huang wen hui wrote:
Mabey I'm a bit slow right now, but I'm unsure what you're trying to
do in this example concerning sleep ? Why is this commented out ?
[example reformatted]
> import java.util.*;
> import cn.gd.util.Timer;
> import cn.gd.util.TimerListener;
>
> import java.sql.*;
>
> public class TestTimer implements cn.gd.util.TimerListener {
>
> Timer timer = new Timer(this,20);
>
> public TestTimer() {
> timer.start();
> }
>
> public synchronized void TimerEvent(Object object) {}
>
> public void destoryTimer() {
> timer.quit();
> }
>
> public void query(){
> try {
> Class.forName("org.gjt.mm.mysql.Driver").newInstance();
>
> Connection conn =
> DriverManager.getConnection("jdbc:mysql://localhost/seismic?user=test&password=test");
> String sql = "select * from station";
> Statement st = conn.createStatement();
> ResultSet rs = null;
>
> for(int i=0;i<100;i++) {
> rs = st.executeQuery(sql);
> while(rs.next()) {
> String sta = rs.getString("sta");
> //System.out.println("sta is: "+sta);
> }
> rs.close();
> }
>
> st.close();
> conn.close();
>
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> public static void main(String[] args) throws Exception {
> TestTimer tt = new TestTimer();
> long now = new java.util.Date().getTime();
> //Thread.sleep(60*1000);
> tt.query();
> System.err.println("query elapse time: "+ (new
> java.util.Date().getTime() - now));
> tt.destoryTimer();
> }
> }
>
>
> public class Timer extends Thread {
> private static ThreadGroup tGroup = new ThreadGroup("Timer");
> // TimerListener to receive TimerEvent notifications
> TimerListener m_timerListener;
>
> // Number of seconds in each timer cycle
> int m_cycle;
>
> // Object to be supplied with the TimerEvent notification
> Object m_object;
> private boolean bQuit = false;
>
> public Timer(TimerListener timerListener, int cycle) {
> super(tGroup,"TimerThread");
> m_timerListener = timerListener;
> m_cycle = cycle;
> m_object = null;
> }
>
> public Timer(TimerListener timerListener, int cycle, Object object) {
> super(tGroup,"TimerThread");
> m_timerListener = timerListener;
> m_cycle = cycle;
> m_object = object;
> }
>
> public void run(){
> this.setName("TimerThread");
> // Loop until stopped
> while (!bQuit) {
> try {
> // Sleep for the clock cycle
> sleep(m_cycle * 1000);
> } catch (InterruptedException ex) {}
>
> // Fire a TimerEvent
> if (m_timerListener != null) {
> m_timerListener.TimerEvent(m_object);
> }
> }
> }
>
> public void quit() {
> bQuit = true;
> }
> }
>
> public interface TimerListener
> {
> void TimerEvent(Object object);
> }
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020814105205.GA5605>
