有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JAVAlang.RuntimeException:注册MBean、com时发生异常。刻度7。卡桑德拉。佩洛普斯。pool:type=PooledNodemy\u keyspacelocalhost

我正在做一个项目,我需要将数据插入Cassandra数据库。因此,我使用了Pelops client

我有一个多线程代码,它将使用Pelops client插入Cassandra数据库。我用ExecutorService来做这个

在我的程序中,每个线程都会在某个范围内工作,比如

Thread1 will work on 1 to 20
Thread2 will work on 21 to 40
...
...

下面是我用来插入Cassandra数据库的代码-

private static int noOfThreads = 5;
private static int noOfTasks = 100;
private static int startRange = 1;

    public static void main(String[] args) {

        LOG.info("Loading data in Cassandra database..!!");

        ExecutorService service = Executors.newFixedThreadPool(noOfThreads);

        try {
            // queue some tasks
            for (int i = 0, nextId = startRange; i < noOfThreads; i++, nextId += noOfTasks) {

                service.submit(new CassandraTask(nextId, noOfTasks));
            }

            service.shutdown();

            service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
        } catch (InterruptedException e) {
            LOG.warn("Threw a Interrupted Exception in" + CNAME + ".PelopsLnPClient: boss told me to stop...Not my fault!!");
        } catch (Exception e) {
            LOG.error("Threw a Exception in" + CNAME + e);
        } 
    }

下面是实现Runnable interfaceCassandraTask class

class CassandraTask implements Runnable {

    private final int id;
    private final int noOfTasks;

    private final String nodes = "localhost";
    private final String thrift_connection_pool = "Test Cluster";
    private final String keyspace = "my_keyspace";
    private final String column_family = "PROFILE_USER";

        public CassandraTask(int nextId, int noOfTasks) {
            this.id = nextId;
            this.noOfTasks = noOfTasks;

        }


        public void run() {

            try {

                cassandraConnection();
                Mutator mutator = Pelops.createMutator(thrift_connection_pool);

                for (int userId = id; userId < id + noOfTasks; userId++) {

                    mutator.writeColumns(column_family, String.valueOf(userId),
                            mutator.newColumnList(
                                    mutator.newColumn("unt", "{\"lv\":[{\"v\":{\"regSiteId\":null,\"userState\":null,\"userId\":" + userId + "},\"cn\":1}],\"lmd\":20130206211109}"), 
                                    mutator.newColumn("rtising", "{\"lv\":[{\"v\":{\"thirdPartyAdsOnhostdomain\":null,\"hostdomainAdsOnThirdParty\":null,\"userId\":" + userId + "},\"cn\":2}],\"lmd\":20130206211109}"), 
                                    mutator.newColumn("selling_price_main_cats", "{\"lv\":[{\"v\":{\"regSiteId\":null,\"userState\":null,\"userId\":" + userId + "},\"cn\":1}],\"lmd\":20130206211109}"), 
                                    mutator.newColumn("and_keyword_rules", "{\"lv\":[{\"v\":{\"regSiteId\":null,\"userState\":null,\"userId\":" + userId + "},\"cn\":1}],\"lmd\":20130206211109}"), 
                                    mutator.newColumn("categories_purchased", "{\"lv\":[{\"v\":{\"regSiteId\":null,\"userState\":null,\"userId\":" + userId + "},\"cn\":1}],\"lmd\":20130206211109}"), 
                                    mutator.newColumn("omer_service", "{\"lv\":[{\"v\":{\"regSiteId\":null,\"userState\":null,\"userId\":" + userId + "},\"cn\":1}],\"lmd\":20130206211109}"), 
                                    mutator.newColumn("graphic", "{\"lv\":[{\"v\":{\"regSiteId\":null,\"userState\":null,\"userId\":" + userId + "},\"cn\":1}],\"lmd\":20130206211109}"), 
                                    mutator.newColumn("rite_searches", "{\"lv\":[{\"v\":{\"regSiteId\":null,\"userState\":null,\"userId\":" + userId + "},\"cn\":1}],\"lmd\":20130206211109}")
                                    ));
                }

                mutator.execute(ConsistencyLevel.ONE);

            } catch (Exception e) {
                System.err.println("Threw a Exception in " + e);
            } finally {
                Pelops.shutdown();
            }
        }

        /**
         * Making a Cassandra Connection by adding nodes
         *
         /
        private void cassandraConnection() {

            Cluster cluster = new Cluster(nodes, 9160);
            Pelops.addPool(thrift_connection_pool, cluster, keyspace);

        }
    }

每当我运行上面的程序时,我总是得到下面的异常-

Threw a Exception in java.lang.RuntimeException: exception while registering MBean, com.scale7.cassandra.pelops.pool:type=PooledNode-my_keyspace-localhost

有人能帮我解决这个问题吗?我到底做错了什么?我相信我在这里犯了一些小错误?如果我跑得很慢,那么我不会出现这种异常。我的意思是,在代码中放置断点。真奇怪

我和卡桑德拉一起工作1.2.3

任何帮助都将不胜感激


共 (1) 个答案

  1. # 1 楼答案

    您使用的是哪个客户端版本?在我看来,每个线程都创建了一个池(同名!)卡桑德拉和每个人关闭Pelops客户端

    在main类中移动池创建,只创建一个池,并从线程访问它,而不要调用Pelops。shutdown()直到最后一个线程执行execute方法

    卡洛