java network_Java NetworkServerControl.ping方法代码示例

import org.apache.derby.drda.NetworkServerControl; //导入方法依赖的package包/类

@BeforeClass

public static void startDatabase() throws Exception {

ServerSocket socket = new ServerSocket(0);

port = socket.getLocalPort();

socket.close();

LOG.info("Starting Derby database on {}", port);

System.setProperty("derby.stream.error.file", "target/derby.log");

derbyServer = new NetworkServerControl(InetAddress.getByName("localhost"), port);

StringWriter out = new StringWriter();

derbyServer.start(new PrintWriter(out));

boolean started = false;

int count = 0;

// Use two different methods to detect when server is started:

// 1) Check the server stdout for the "started" string

// 2) wait up to 15 seconds for the derby server to start based on a ping

// on faster machines and networks, this may return very quick, but on slower

// networks where the DNS lookups are slow, this may take a little time

while (!started && count < 30) {

if (out.toString().contains("started")) {

started = true;

} else {

count++;

Thread.sleep(500);

try {

derbyServer.ping();

started = true;

} catch (Throwable t) {

//ignore, still trying to start

}

}

}

dataSource = new ClientDataSource();

dataSource.setCreateDatabase("create");

dataSource.setDatabaseName("target/beam");

dataSource.setServerName("localhost");

dataSource.setPortNumber(port);

readTableName = JdbcTestHelper.getTableName("UT_READ");

JdbcTestHelper.createDataTable(dataSource, readTableName);

addInitialData(dataSource, readTableName);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值