如何优雅地结束测试客户端

时间:2018-06-01 09:21:03

标签: java cumulocity

我有一个简单的积水测试客户端。代码运行正常,但代码完成时jvm不会停止。 一些线程仍在运行:MultiThreadedHttpConnectionManager。

如何正常关闭分配的开放连接:

InventoryApi inventory = platform.getInventoryApi() ?

_

...
platform = new PlatformImpl(App.C8Y_URL, new CumulocityCredentials(App.C8Y_USER, App.C8Y_PWD));
InventoryApi inventory = platform.getInventoryApi();

GId testId = new GId("123456");
ManagedObjectRepresentation testDevice = inventory.get(testId);
MeasurementApi mApi = platform.getMeasurementApi();

MeasurementRepresentation measurement = new MeasurementRepresentation();
measurement.setType("c8y_SampleRate");
measurement.setSource(testDevice);

DateTime time = new DateTime();
System.out.println("time " + time.toString());
measurement.setDateTime(time);
Map<String, Object> flowRateFragment = App.createFlowRateFragment(new BigDecimal(20.5));
measurement.set(flowRateFragment, "c8y_SampleRate");

MeasurementRepresentation measurementCreation = mApi.create(measurement);
...

2 个答案:

答案 0 :(得分:0)

正常关闭您的QuarkIoE客户电话platform.close()

答案 1 :(得分:0)

没有你在代码完成后无法退出。使用QuarkIoE代理连续运行,它们不会停止线程。 如果你想退出,那么你可以使用

System.exit(0); //Change the status code accordingly