1

I have a simple cumulocity test client. The code runs fine but the jvm does not stop when the code finishes. Some threads are still running: MultiThreadedHttpConnectionManager.

How to gracefully shutdown the open connections allocated by:

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);
...
pmahler
  • 11
  • 1

2 Answers2

1

To gracefully shutdown your Cumulocity client call platform.close().

l2p
  • 420
  • 3
  • 9
  • This results in an exception `Exception in thread "pool-1-thread-1" java.lang.RuntimeException: at com.cumulocity.sdk.client.buffering.MemoryBasedPersistentProvider.poll(MemoryBasedPersistentProvider.java:43) at com.cumulocity.sdk.client.buffering.BufferProcessor$1.run(BufferProcessor.java:42) Caused by: java.lang.InterruptedException at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2014)` – pmahler Jun 06 '18 at 13:25
0

NO you cannot exit after the code finished. Cumulocity agent is made to run continuously so, they won't stop the thread. If you want out exit then you have use

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

Dhanasekaran Don
  • 294
  • 1
  • 14