Created
June 1, 2017 08:43
-
-
Save noctarius/e29a693115ee9de01817119d0c42eaa1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mc; | |
import com.hazelcast.client.HazelcastClient; | |
import com.hazelcast.core.HazelcastInstance; | |
import com.hazelcast.core.IMap; | |
import com.hazelcast.core.ITopic; | |
import java.util.UUID; | |
public class MCDemo { | |
public static void main(String[] args) { | |
HazelcastInstance client = HazelcastClient.newHazelcastClient(); | |
IMap<Integer, String> map = client.getMap("jax-2017"); | |
ITopic<String> topic = client.getTopic("jax-2017"); | |
topic.addMessageListener((m) -> {/*/dev/null*/}); | |
new Thread( | |
() -> loop(() -> map.put(key(), value())) | |
).start(); | |
new Thread( | |
() -> loop(() -> map.get(key())) | |
).start(); | |
new Thread( | |
() -> loop(() -> map.remove(key())) | |
).start(); | |
new Thread( | |
() -> loop(() -> topic.publish(UUID.randomUUID().toString())) | |
).start(); | |
} | |
private static void sleep() { | |
try { | |
Thread.sleep((int) (Math.random() * 100)); | |
} catch (Exception e) {} | |
} | |
private static int key() { | |
return (int) (Math.random() * 1000000); | |
} | |
private static String value() { | |
return UUID.randomUUID().toString(); | |
} | |
private static void loop(Runnable runnable) { | |
while (true) { | |
runnable.run(); | |
sleep(); | |
} | |
} | |
private static void loop2(Runnable runnable) { | |
while (true) { | |
runnable.run(); | |
//sleep(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment