Following this guide, I am trying to print out a list of databases.
public class Main{
public static void main(String[] args){
System.out.println("Testing MongoDB.");
MongoClient mongoClient = new MongoClient("localhost", 27017);
MongoDatabase database = mongoClient.getDatabase("myMongoDb");
System.out.println("Connect to database successfully.");
database.getCollection("Customers");
System.out.println("Created Customer collection successfully.");
MongoCursor<String> dbsCursor = database.listCollectionNames().iterator();
while(dbsCursor.hasNext()){
System.out.println(dbsCursor.next());
}
database.listCollectionNames().forEach((Consumer<String>) System.out::println);
mongoClient.listDatabaseNames().forEach((Consumer<String>) System.out::println);
}
}
I tested with a regular iterator as well but only get the following output.
> Task :run
Testing MongoDB.
Dec 27, 2017 1:02:49 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
Connect to database successfully.
Created Customer collection successfully.
Dec 27, 2017 1:02:49 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Cluster description not yet available. Waiting for 30000 ms before timing out
Dec 27, 2017 1:02:49 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:1, serverValue:23}] to localhost:27017
Dec 27, 2017 1:02:49 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 6, 0]}, minWireVersion=0, maxWireVersion=6, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=2474145}
Dec 27, 2017 1:02:49 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:2, serverValue:24}] to localhost:27017
admin
config
local
Expected output, as per the guide, would be something like this:
The output will be:
local 0.000GB
myMongoDb 0.000GB
I'm not too sure what i'm doing wrong. Additionally, is there a way to silence the logging such that I can inspect my output easier?
If you need to check if a collection exists, try this:
boolean collectionExists = client.getDatabase("dbName").listCollectionNames()
.into(new ArrayList<String>()).contains("collectionName")
Related
I want consum a rest service in http://localhost:8080/ with apache-camel using jetty. But this code not produce any request to the API. I am beginner in apache-camel and I want use to orchestation of differents microservices.
Code:
package example;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
public class ejemplo {
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
context.setTracing(true);
context.addRoutes(new RouteBuilder(){
#Override
public void configure() throws Exception {
from("direct:start")
.log("Http Route started")
.setHeader(Exchange.HTTP_METHOD,simple("GET"))
.setHeader(Exchange.CONTENT_TYPE,simple("application/json"))
.to("jetty:http://0.0.0.0:8080/")
.process(new Processor(){
public void process(Exchange exchange) throws Exception {
System.out.println("I am a process....");
String msg = exchange.getIn().getBody().toString();
System.out.println(msg);
}
});
}
});
context.start();
}
}
Log:
sep 24, 2019 7:57:05 PM org.apache.camel.impl.DefaultCamelContext start
INFORMACIÓN: Apache Camel 2.17.1 (CamelContext: camel-1) is starting
sep 24, 2019 7:57:05 PM org.apache.camel.impl.DefaultCamelContext doStartCamel
INFORMACIÓN: Tracing is enabled on CamelContext: camel-1
sep 24, 2019 7:57:05 PM org.apache.camel.management.ManagedManagementStrategy doStart
INFORMACIÓN: JMX is enabled
sep 24, 2019 7:57:05 PM org.apache.camel.impl.converter.DefaultTypeConverter doStart
INFORMACIÓN: Loaded 208 type converters
sep 24, 2019 7:57:05 PM org.apache.camel.impl.DefaultRuntimeEndpointRegistry doStart
INFORMACIÓN: Runtime endpoint registry is in extended mode gathering usage statistics of all incoming and outgoing endpoints (cache limit: 1000)
sep 24, 2019 7:57:05 PM org.apache.camel.impl.DefaultCamelContext doStartCamel
INFORMACIÓN: AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
sep 24, 2019 7:57:05 PM org.apache.camel.impl.DefaultCamelContext doStartCamel
INFORMACIÓN: StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
sep 24, 2019 7:57:05 PM org.eclipse.jetty.util.log.Log initialized
INFORMACIÓN: Logging initialized #1372ms
sep 24, 2019 7:57:06 PM org.apache.camel.impl.DefaultCamelContext doStartOrResumeRouteConsumers
INFORMACIÓN: Route: route1 started and consuming from: Endpoint[direct://httpRouter]
sep 24, 2019 7:57:06 PM org.apache.camel.impl.DefaultCamelContext start
INFORMACIÓN: Total 1 routes, of which 1 are started.
sep 24, 2019 7:57:06 PM org.apache.camel.impl.DefaultCamelContext start
INFORMACIÓN: Apache Camel 2.17.1 (CamelContext: camel-1) started in 1.466 seconds
This output not produces any response of the API in localhost:8080 but I think that the route is correct. I would want know if there are other ways of consume a rest service of a API REST using apache-camel.
Note that start is just a name and direct component allows you to invoke your route synchronously from other route, it seems like you are not doing just that
To check if the route is correct replace direct in your from endpoint to timer, e.g. from("timer://foo?fixedRate=true&period=10000"), for more details see camel docs
I'm setting up a in-memory cache store using apache ignite in my web application. Where I am starting the ignite node and storing some data in ignite cache store at the start of my application server. while doing so I m able to start ignite node but my app server got stuck in starting mode at the below line of code.
igniteCache.getCache("some_string");
Tried to increase failure timeout.
Tried again after increase the memory.
IgniteConfiguration igniteConfig = new IgniteConfiguration();
igniteConfig.setSystemWorkerBlockedTimeout(60 * 60 * 1000);
StopNodeFailureHandler handler = new org.apache.ignite.failure.StopNodeFailureHandler();
handler.setIgnoredFailureTypes(new HashSet());
igniteConfig.setFailureHandler(handler);
//implementing multiple cache stores
List<CacheConfiguration> list = new ArrayList<CacheConfiguration>();
CacheConfiguration<String, Object> cacheConfig0 = new CacheConfiguration<String, Object>(name);
cacheConfig.setCacheMode(CacheMode.PARTITIONED);
list.add(cacheConfig0);
CacheConfiguration<String, Object> cacheConfig1 = new CacheConfiguration<String, Object>(name);
cacheConfig.setCacheMode(CacheMode.PARTITIONED);
list.add(cacheConfig1);
//here starting the ignite node
ignite = Ignition.start(igniteConfig);
caches = ignite.getOrCreateCaches(list);
below are the exception i m getting while starting the server
*[15:08:12] Topology snapshot [ver=1, locNode=51a25b22, servers=1, clients=0, state=ACTIVE, CPUs=4, offheap=3.0GB, heap=2.5GB]
<Jul 27, 2019 3:08:35,634 PM IST> <Error> <org.apache.ignite.internal.util.typedef.G> <BEA-000000> <Blocked system-critical thread has been detected. This can lead to cluster-wide undefined behaviour [threadName=grid-timeout-worker, blockedFor=13s]>
<Jul 27, 2019 3:08:36,625 PM IST> <Warning> <org.apache.ignite.internal.util.typedef.G> <BEA-000000> <Thread [name="grid-timeout-worker-#23", id=219, state=RUNNABLE, blockCnt=1, waitCnt=43]
>
<Jul 27, 2019 3:08:49,975 PM IST> <Error> <> <BEA-000000> <Critical system error detected. Will be handled accordingly to configured handler [hnd=StopNodeOrHaltFailureHandler [tryStop=false, timeout=0, super=AbstractFailureHandler [ignoredFailureTypes=[SYSTEM_WORKER_BLOCKED, SYSTEM_CRITICAL_OPERATION_TIMEOUT]]], failureCtx=FailureContext [type=SYSTEM_WORKER_BLOCKED, err=class o.a.i.IgniteException: GridWorker [name=grid-timeout-worker, igniteInstanceName=null, finished=false, heartbeatTs=1564220302360]]]
class org.apache.ignite.IgniteException: GridWorker [name=grid-timeout-worker, igniteInstanceName=null, finished=false, heartbeatTs=1564220302360]
at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance$2.apply(IgnitionEx.java:1831)
at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance$2.apply(IgnitionEx.java:1826)
at org.apache.ignite.internal.worker.WorkersRegistry.onIdle(WorkersRegistry.java:233)
at org.apache.ignite.internal.util.worker.GridWorker.onIdle(GridWorker.java:297)
at org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.lambda$new$0(ServerImpl.java:2663)*
As a newbie to MongoDB I'm trying to insert a simple document into my freshly installed mongoDB (v3.2.4). MongoDB Driver 3.2.2 is used.
Here my minimized code:
public <classname>()
{
public static final String COLLECTION_NAME = "logs";
MongoClient mongoClient = new MongoClient("<server-adress>");
MongoDatabase db = mongoClient.getDatabase("test");
Document data = new Document ();
data.append(<whatever>);
//...inserting more into document...
db.getCollection(COLLECTION_NAME).insertOne(data); //collection should be created new
mongoClient.close();
}
The programm is executing, but I'm getting the following errors (and informations) during execution:
Mär 16, 2016 3:50:06 PM com.mongodb.diagnostics.logging.JULLogger log
INFORMATION: Cluster created with settings {hosts=[<server-adress>:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
Mär 16, 2016 3:50:06 PM com.mongodb.diagnostics.logging.JULLogger log
INFORMATION: No server chosen by WritableServerSelector from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, all=[ServerDescription{address=<server-adress>:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
Mär 16, 2016 3:50:07 PM com.mongodb.diagnostics.logging.JULLogger log
INFORMATION: Exception in monitor thread while connecting to server <server-adress>:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:128)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
(...)
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)
at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
... 3 more
Error: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=<server-adress>:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]
The document is also not inserted.
When I'm commenting the line with the insertOne()-command, it disappears. So I assume it isnt' a problem with the connection, is that right?
I've some ideas:
Does it has something to do with asynchronity? I'd be suprized, I said nowhere that I don't want to execute it synchronous.
Are any permissions missing (because of this WritableServerSelector-Thing)?
Does it has to do with the "test"-database?
Are there problems with the stand-alone-mode of MongoDB? (I don't want to use replicasets.)
But for all these ideas I couldn't find real proofs...
(Please improve the question-title, I had no better idea...)
Solved it on my own.
I also should have mentioned, that I'm trying to connect from another machine to the MongoDB-instance. That is not allowed with the MongoDB-presets.
So I had to change in the /etc/mongod.conf File the value behind bindIp from 127.0.0.1 to 0.0.0.0.
[Source]
I am developing a java application that executes ssh commands using Ganymed SSH-2
I need to produce full logs for each sequence of commands, e.g. zip file transfer, unzipping, zipping etc..
Having searched the source code for ch.ethz.ssh2.log.Logger i can set the boolean public static volatile boolean enabled = false; to true
this provides the following output
Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: kex_algo=diffie-hellman-group-exchange-sha1
Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: server_host_key_algo=ssh-rsa
Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: enc_algo_client_to_server=aes128-ctr
Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: enc_algo_server_to_client=aes128-ctr
Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: mac_algo_client_to_server=hmac-sha1-96
Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: mac_algo_server_to_client=hmac-sha1-96
Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: comp_algo_client_to_server=none
Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: comp_algo_server_to_client=none
However I also require ALL level logging for command execution including file transfers.
How do i configure the Logger to produce all the information available?
A little late answer but maybe someone still needs this info.
I managed to get the debug statements visible like this:
public void enableFineLogging() {
try {
ch.ethz.ssh2.log.Logger.enabled = true;
String name = "myDynamicFileNamePart";
FileHandler fileHandler = new FileHandler("./logs/"
+ name + "_SFTP.log", 10000000, 1000, true);
fileHandler.setLevel(Level.FINE);
fileHandler.setFormatter(new SimpleFormatter());
final Logger app = Logger.getLogger("ch.ethz");
app.setLevel(Level.FINE);
app.addHandler(fileHandler);
app.setUseParentHandlers(false);
} catch (Exception e) {
// Catchalog
}
}
With result in file with:
marras 15, 2017 12:16:56 IP. org.slf4j.impl.JCLLoggerAdapter info
INFO: Client identity string: SSH-2.0-SSHJ_0.19.1
marras 15, 2017 12:16:56 IP. org.slf4j.impl.JCLLoggerAdapter info
INFO: Server identity string: SSH-2.0-OpenSSH_6.6.1
marras 15, 2017 12:16:56 IP. org.slf4j.impl.JCLLoggerAdapter debug
FINE: Setting <> to null
marras 15, 2017 12:16:56 IP. org.slf4j.impl.JCLLoggerAdapter debug
FINE: Sending SSH_MSG_KEXINIT
marras 15, 2017 12:16:56 IP. org.slf4j.impl.JCLLoggerAdapter debug
FINE: Setting <> to SOME
marras 15, 2017 12:16:56 IP. org.slf4j.impl.JCLLoggerAdapter debug
FINE: Awaiting <>
marras 15, 2017 12:16:56 IP. org.slf4j.impl.JCLLoggerAdapter debug
FINE: Received SSH_MSG_KEXINIT
Use ConsoleHandler if you wish logs in console.
Also closing the log file needs to be considered with fileHandler.close() after you quit logging.
Tune the log level by choosing from SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL
How can I configure Hazelcast (optimally the version I currently use: 3.1.2) to run 2 hazelcast instances on a single machine, and block the first instance during startup until both instances are present?
hazelcast.initial.min.cluster.size
The blocking behavior described above can be implemented with the help of hazelcast.initial.min.cluster.size when running both instances on different machines: With the configuration:
Config cfg = new Config();
cfg.setProperty("hazelcast.initial.min.cluster.size",
Integer.toString(minimumInitialMembersInHazelCluster));
cfg.getGroupConfig().setName(clusterName);
hazelInst = Hazelcast.newHazelcastInstance(cfg);
run on different machines, I get the output
Apr 15, 2014 9:31:39 AM com.hazelcast.instance.DefaultAddressPicker
INFO: Prefer IPv4 stack is true.
Apr 15, 2014 9:31:39 AM com.hazelcast.instance.DefaultAddressPicker
INFO: Picked Address[192.168.31.105]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
Apr 15, 2014 9:31:40 AM com.hazelcast.system
INFO: [192.168.31.105]:5701 [dev] Hazelcast Community Edition 3.1.2 (20131120) starting at Address[192.168.31.105]:5701
Apr 15, 2014 9:31:40 AM com.hazelcast.system
INFO: [192.168.31.105]:5701 [dev] Copyright (C) 2008-2013 Hazelcast.com
Apr 15, 2014 9:31:40 AM com.hazelcast.instance.Node
INFO: [192.168.31.105]:5701 [dev] Creating MulticastJoiner
Apr 15, 2014 9:31:40 AM com.hazelcast.core.LifecycleService
INFO: [192.168.31.105]:5701 [dev] Address[192.168.31.105]:5701 is STARTING
Apr 15, 2014 9:31:43 AM com.hazelcast.cluster.MulticastJoiner
INFO: [192.168.31.105]:5701 [dev]
Members [1] {
Member [192.168.31.105]:5701 this
}
Apr 15, 2014 9:31:43 AM com.hazelcast.core.LifecycleService
INFO: [192.168.31.105]:5701 [dev] Address[192.168.31.105]:5701 is STARTED
Apr 15, 2014 9:31:43 AM HazelMultiInstanceExp <init>
SEVERE: debug: joined via JoinConfig{multicastConfig=MulticastConfig [enabled=true, multicastGroup=224.2.2.3, multicastPort=54327, multicastTimeToLive=32, multicastTimeoutSeconds=2, trustedInterfaces=[]], tcpIpConfig=TcpIpConfig [enabled=false, connectionTimeoutSeconds=5, members=[], requiredMember=null], awsConfig=AwsConfig{enabled=false, region='us-east-1', securityGroupName='null', tagKey='null', tagValue='null', hostHeader='ec2.amazonaws.com', connectionTimeoutSeconds=5}} with 1 members.
Apr 15, 2014 9:31:43 AM com.hazelcast.instance.DefaultAddressPicker
INFO: Prefer IPv4 stack is true.
Apr 15, 2014 9:31:43 AM com.hazelcast.instance.DefaultAddressPicker
INFO: Picked Address[192.168.31.105]:5702, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5702], bind any local is true
Apr 15, 2014 9:31:43 AM com.hazelcast.system
INFO: [192.168.31.105]:5702 [dev] Hazelcast Community Edition 3.1.2 (20131120) starting at Address[192.168.31.105]:5702
Apr 15, 2014 9:31:43 AM com.hazelcast.system
INFO: [192.168.31.105]:5702 [dev] Copyright (C) 2008-2013 Hazelcast.com
Apr 15, 2014 9:31:43 AM com.hazelcast.instance.Node
INFO: [192.168.31.105]:5702 [dev] Creating MulticastJoiner
Apr 15, 2014 9:31:43 AM com.hazelcast.core.LifecycleService
INFO: [192.168.31.105]:5702 [dev] Address[192.168.31.105]:5702 is STARTING
Apr 15, 2014 9:31:43 AM com.hazelcast.nio.SocketConnector
INFO: [192.168.31.105]:5702 [dev] Connecting to /192.168.31.105:5701, timeout: 0, bind-any: true
Apr 15, 2014 9:31:43 AM com.hazelcast.nio.SocketAcceptor
INFO: [192.168.31.105]:5701 [dev] Accepting socket connection from /192.168.31.105:60803
Apr 15, 2014 9:31:43 AM com.hazelcast.nio.TcpIpConnectionManager
INFO: [192.168.31.105]:5702 [dev] 60803 accepted socket connection from /192.168.31.105:5701
Apr 15, 2014 9:31:43 AM com.hazelcast.nio.TcpIpConnectionManager
INFO: [192.168.31.105]:5701 [dev] 5701 accepted socket connection from /192.168.31.105:60803
Apr 15, 2014 9:31:49 AM com.hazelcast.cluster.ClusterService
INFO: [192.168.31.105]:5702 [dev]
Members [2] {
Member [192.168.31.105]:5701
Member [192.168.31.105]:5702 this
}
but run with two instances on one machine, I get
Apr 15, 2014 9:25:14 AM com.hazelcast.instance.DefaultAddressPicker
INFO: Prefer IPv4 stack is true.
Apr 15, 2014 9:25:14 AM com.hazelcast.instance.DefaultAddressPicker
INFO: Picked Address[192.168.31.105]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
Apr 15, 2014 9:25:15 AM com.hazelcast.system
INFO: [192.168.31.105]:5701 [test3] Hazelcast Community Edition 3.1.2 (20131120) starting at Address[192.168.31.105]:5701
Apr 15, 2014 9:25:15 AM com.hazelcast.system
INFO: [192.168.31.105]:5701 [test3] Copyright (C) 2008-2013 Hazelcast.com
Apr 15, 2014 9:25:15 AM com.hazelcast.instance.Node
INFO: [192.168.31.105]:5701 [test3] Creating MulticastJoiner
Apr 15, 2014 9:25:15 AM com.hazelcast.core.LifecycleService
INFO: [192.168.31.105]:5701 [test3] Address[192.168.31.105]:5701 is STARTING
Apr 15, 2014 9:25:18 AM com.hazelcast.cluster.MulticastJoiner
INFO: [192.168.31.105]:5701 [test3]
Members [1] {
Member [192.168.31.105]:5701 this
}
Apr 15, 2014 9:25:18 AM com.hazelcast.instance.HazelcastInstanceImpl
INFO: [192.168.31.105]:5701 [test3] HazelcastInstance waiting for cluster size of 2
with the last INFO message repeated ad infinitum.
So the cluster size is the number of nodes in the cluster, not the number of hazelcast instances?
Blocking behavior on a single machine
I use cfg.setProperty("hazelcast.initial.min.cluster.size","2") so the two distributed instances start my distributed algorithm synchronously. Furthermore, it solves the problem that some hazelcast members are not found, see https://stackoverflow.com/a/20716919/750378.
So how do I avoid both problems when running on a single machine? It would be great if the cluster size would simple be the number of running hazelcast instances. Then I could keep my configuration above no matter how I deploy my two instances (on 1 or 2 machines).
Update
I have posted an issue about the cluster size at https://github.com/hazelcast/hazelcast/issues/2292.
You could use the same machine to run multiples Hazelcast instance. Under the hoods, Hazelcast binds differents ports for each instance.
Following, a simple test with two instances:
HazelcastInstance firstInstance = Hazelcast.newHazelcastInstance(new Config());
HazelcastInstance secondInstance = Hazelcast.newHazelcastInstance(new Config());
// Introducing a sample data in a map using the first instance
firstInstance.getMap("TEST_MAP").put("key", "test_value");
// Prints the value using the second instance. The result will be 'test_value'
System.out.println(secondInstance.getMap("TEST_MAP").get("key"));
When this code starts the console output is:
Members [2] {
Member [192.168.216.1]:5702
Member [192.168.216.1]:5703 this
}
As you can see, two instances were registered in the same IP but different ports.
You should start instances in different threads.
See following test:
public static void main(String[] args) throws InterruptedException {
final Config cfg = new Config();
cfg.setProperty(GroupProperties.PROP_INITIAL_MIN_CLUSTER_SIZE, "2");
Runnable runnable = new Runnable() {
public void run() {
final HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
IMap<Object, Object> map = instance.getMap("map");
for (int i = 0; i < 100; i++) {
map.put(i, i);
System.out.println("put:" + i);
}
}
};
Thread thread1 = new Thread(runnable);
Thread thread2 = new Thread(runnable);
thread1.start();
Thread.sleep(1000);
thread2.start();
}
Please see this thread for more information. Based on the info there, your best bet is to:
make sure you're using a configuration which allows for two machines in the cluster, on the same pc (check out the sample config file attached to that thread)
Run both machines on the same JVM (rather than firing up two separate JVMs)
Are running a fairly recent version (3.1.2 should be fine)
Starting two JVMs on the same physical machine might work sometimes if you make sure they don't have conflicting port settings, but you'll likely run into various problems (ie, i bet they won't be able to properly listen to the same multicast port). I'd advise against that approach.