Source:
<code>public ExampleDTLSClient() { InputStream inTrust = null; InputStream in = null; try { KeyStore keyStore = KeyStore.getInstance("JKS"); in = getClass().getClassLoader().getResourceAsStream(KEY_STORE_LOCATION); keyStore.load(in, KEY_STORE_PASSWORD.toCharArray()); in.close(); KeyStore trustStore = KeyStore.getInstance("JKS"); inTrust = getClass().getClassLoader().getResourceAsStream(TRUST_STORE_LOCATION); trustStore.load(inTrust, TRUST_STORE_PASSWORD.toCharArray()); Certificate[] trustedCertificates = new Certificate[1]; trustedCertificates[0] = trustStore.getCertificate("root"); DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(); builder.setPskStore(new StaticPskStore("Client_identity", "secretPSK".getBytes())); builder.setIdentity((PrivateKey) keyStore.getKey("client", KEY_STORE_PASSWORD.toCharArray()), keyStore.getCertificateChain("client"), true); builder.setTrustStore(trustedCertificates); builder.setEnableAddressReuse(false); dtlsConnector = new DTLSConnector(builder.build()); <START> dtlsConnector.setExecutor(new StripedExecutorService(2)); <END> dtlsConnector.setRawDataReceiver(new RawDataChannel() { @Override public void receiveData(RawData raw) { long c = count.incrementAndGet(); LOG.log(Level.INFO, "Received response: {0} {1}", new Object[]{new String(raw.getBytes()), c}); latch.countDown(); if (0 < latch.getCount()) { dtlsConnector .send(new RawData(("HELLO WORLD " + c + ".").getBytes(), raw.getInetSocketAddress())); } else { dtlsConnector.destroy(); } } }); } catch (GeneralSecurityException | IOException e) { LOG.log(Level.SEVERE, "Could not load the keystore", e); } finally { try { if (inTrust != null) { inTrust.close(); } if (in != null) { in.close(); } } catch (IOException e) { LOG.log(Level.SEVERE, "Cannot close key store file", e); } } }</code><technical_language>builder.setConnectionThreadCount(2);</technical_language>

Target:
public ExampleDTLSClient() { InputStream inTrust = null; InputStream in = null; try { KeyStore keyStore = KeyStore.getInstance("JKS"); in = getClass().getClassLoader().getResourceAsStream(KEY_STORE_LOCATION); keyStore.load(in, KEY_STORE_PASSWORD.toCharArray()); in.close(); KeyStore trustStore = KeyStore.getInstance("JKS"); inTrust = getClass().getClassLoader().getResourceAsStream(TRUST_STORE_LOCATION); trustStore.load(inTrust, TRUST_STORE_PASSWORD.toCharArray()); Certificate[] trustedCertificates = new Certificate[1]; trustedCertificates[0] = trustStore.getCertificate("root"); DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(); builder.setPskStore(new StaticPskStore("Client_identity", "secretPSK".getBytes())); builder.setIdentity((PrivateKey) keyStore.getKey("client", KEY_STORE_PASSWORD.toCharArray()), keyStore.getCertificateChain("client"), true); builder.setTrustStore(trustedCertificates); builder.setEnableAddressReuse(false); builder.setConnectionThreadCount(2); dtlsConnector = new DTLSConnector(builder.build()); dtlsConnector.setRawDataReceiver(new RawDataChannel() { @Override public void receiveData(RawData raw) { long c = count.incrementAndGet(); LOG.log(Level.INFO, "Received response: {0} {1}", new Object[] { new String(raw.getBytes()), c }); latch.countDown(); if (0 < latch.getCount()) { dtlsConnector .send(new RawData(("HELLO WORLD " + c + ".").getBytes(), raw.getInetSocketAddress())); } else { dtlsConnector.destroy(); } } }); } catch (GeneralSecurityException | IOException e) { LOG.log(Level.SEVERE, "Could not load the keystore", e); } finally { try { if (inTrust != null) { inTrust.close(); } if (in != null) { in.close(); } } catch (IOException e) { LOG.log(Level.SEVERE, "Cannot close key store file", e); } } }