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

📄 timedconnect.java

📁 java在线商店的源代码。编写十分规范的哦
💻 JAVA
字号:
/**
 * Copyright (c) 1996-2004 Borland Software Corporation.  All Rights Reserved.
 * 
 * This SOURCE CODE FILE, which has been provided by Borland Software as part
 * of a Borland Software product for use ONLY by licensed users of the product,
 * includes CONFIDENTIAL and PROPRIETARY information of Borland Software.  
 *
 * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 
 * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
 * THE PRODUCT.
 *
 * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND SOFTWARE, ITS
 * RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY
 * CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR
 * DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES
 * ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR
 * DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR
 * DERIVED FROM THIS SOURCE CODE FILE.
 */
//------------------------------------------------------------------------------
// Copyright (c) 1996-2004 Borland Software Corporation.  All Rights Reserved.
//------------------------------------------------------------------------------

package com.borland.samples.creditapproval.server;

import java.util.*;

import com.borland.dx.sql.dataset.*;
import com.borland.dx.dataset.*;

/**
* TimedConnect class repeatedly attempts to connect to a database
* every X number of seconds for a total specified number of seconds.
* If unable to connect, the Dataset/SQLException is rethrown.
*/
public class TimedConnect {

  public TimedConnect(Database connectDb, int retrySeconds, int totalSeconds )
       throws DataSetException {

    long current;
    long nextRetry;

    long end = System.currentTimeMillis() + totalSeconds * 1000l;

    do {
      try {
        connectDb.openConnection();
        break;
      } catch (DataSetException e) {
        System.err.println(e);

        // Pause for the specified number of seconds before attempting
        // to connect again
        nextRetry = System.currentTimeMillis() + retrySeconds * 1000l;

        do {

          current = System.currentTimeMillis();

          // Re-throw the exception if the maximum amount of
          // time specified to attempt a connection has expired.
          if (current >= end) throw e;

        } while (current < nextRetry );
      }
    } while (current < end);
  }
}

⌨️ 快捷键说明

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