⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fixedwaitthread.java

📁 Java示例100
💻 JAVA
字号:
/** * This class is used by CCache4.java, CCache5.java, and CCache6.java, * and CCache7.java **/import java.sql.*;import javax.sql.*;import oracle.jdbc.*;import oracle.jdbc.pool.*;/** * Getting connections through various threads */class FixedWaitThread extends Thread{  Connection conn = null;  // a logical connection to be obtained in this thread  OracleConnectionCacheImpl ods = null;  static boolean greenLight = false;  // a signal to control the thread  int threadid = 0;                   // unique to each thread  static int threadnum = 0;           // record how many threads created  static int connum = 0;      // record how many connections made                              // throught FixedWaitThread  boolean connected = false;  // indicate whether this thread connection                              // creation success  public FixedWaitThread ()  {  }  public FixedWaitThread (OracleConnectionCacheImpl o, int i)  {      incrthreadnum();      threadid = i;      ods = o;  }  synchronized static void incrthreadnum ()  {      ++threadnum;  }  synchronized static int getthreadnum ()  {      return threadnum;  }  synchronized static void incrconnum ()  {      ++connum;  }  synchronized static void decrconnum ()  {      --connum;  }  synchronized static int getconnum ()  {      return connum;  }  boolean getconnected ()  {      return connected;  }  void closeconnection ()  {      if ( getconnected() )      {          connected = false;          decrconnum ();          try { conn.close(); } catch (SQLException e)          { e.printStackTrace(); }           conn = null;      }  }  synchronized static void setGreenLight ()  {     greenLight = true;  }  boolean getGreenLight ()  {      return greenLight;  }  public void run ()  {      while (!getGreenLight())        yield();      try      {          conn = ods.getConnection();      } catch (SQLException e)      {          // ORA-17126=Fixed Wait timeout elapsed,          // an expected exception          if ( e.getErrorCode()  != 17126 )               e.printStackTrace();      }      long t = System.currentTimeMillis();      if ( conn != null )      {          connected = true;          incrconnum ();          System.out.println("Thread " + threadid + " get connection at " +                             (new Timestamp (t)).toString());      }      else          System.out.println("Thread " + threadid + " get connection Failed");  } // end of run ()} // end of class FixedWaitThread

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -