2

我在 tomcat 服务器上运行 java maven 项目。这是一个使用气氛框架的聊天应用程序的服务器端脚本。

socket.fire("message="+"testmessage")从客户端触发到服务器时,有时以下错误会进入 tomcat 控制台。

Oct 16, 2013 7:26:39 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.

这个错误是随机出现的。

有时服务器崩溃,导致所有消息传输失败。

我正在使用以下服务器端代码进行消息广播:@Path("/pubsub/{topic}") public class JerseyPubSub {

private @PathParam("topic")
Broadcaster topic;

@GET
public SuspendResponse<String> subscribe() {
    return new SuspendResponse.SuspendResponseBuilder<String>()
            .broadcaster(topic)
            .outputComments(true)
            .addListener((AtmosphereResourceEventListener) new EventsLogger())
            .build();
}

@POST
@Broadcast
@Produces("text/html;charset=ISO-8859-1")
public Broadcastable publish(@FormParam("message") String message) throws JSONException, IOException, SQLException {
    JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost", 6379);
    Jedis jedis = pool.getResource();

    int remote_id = 0;
    int local_id = 0;
    int from = 0;
    int to = 0;
    String msg = null;
    int chatroomid = 0;
    JSONObject json = new JSONObject();
    JSONObject sender_respondejson = new JSONObject();
    String msg_for = null;
    String msg_content = null;
    String msg_type = null;

    //{"local_id": "123", "from": "100", "to": "200", "message": "'+getElementByIdValue("phrase")+'", "msg_for": "0", "msg_content": "0", "msg_type": "0"}
    JSONObject msgObject = new JSONObject(message.toString());
    //if(msgObject.has("msg_for")){
    msg_for = msgObject.getString("msg_for");
    msg_content = msgObject.getString("msg_content");
    msg_type = msgObject.getString("msg_type");
    if (msg_for.equals("0")) {
        //One-to-one message
        if (msg_content.equals("0")) {
            if (msg_type.equals("0")) {
                local_id = msgObject.getInt("local_id");
                from = msgObject.getInt("from");
                to = msgObject.getInt("to");
                msg = msgObject.getString("message");

                //json.put("local_id", local_id);
                json.put("from", from+"");
                json.put("to", to+"");
                json.put("message", msg);
                Date now = new Date();
                Long sent = new Long(now.getTime() / 1000);
                json.put("sent", sent);

                String key = (from + "_" + to);
                String rkey = (to + "_" + from);

                String val = json.toString();

                jedis.rpush(key, val);
                jedis.rpush(rkey, val);

                String history = (jedis.lrange(key, 0, 10)).toString();
                jedis.set(msg, history);

                MysqlConnection mysqlcon = new MysqlConnection();
                String lastmessageid = mysqlcon.send_message(message, sent);

                sender_respondejson.put("remote_id", lastmessageid);
                sender_respondejson.put("local_id", local_id);
                sender_respondejson.put("to", to+"");
                sender_respondejson.put("msg_for", msg_for);
                sender_respondejson.put("msg_content", msg_content);
                sender_respondejson.put("msg_type", "1");

                json.put("remote_id", lastmessageid);
                json.put("msg_for", msg_for);
                json.put("msg_content", msg_content);
                json.put("msg_type", msg_type);

                jedis.publish(to + "", json.toString());
            } else if (msg_type.equals("2")) {
                //{"to": "1", "remote_id": "234", "msg_content": "0", "msg_for": "0", "msg_type": "2"}
                from = msgObject.getInt("from");
                to = msgObject.getInt("to");
                remote_id = msgObject.getInt("remote_id");
                json.put("remote_id", remote_id+"");
                json.put("to", to+"");
                json.put("msg_for", msg_for);
                json.put("msg_content", msg_content);
                json.put("msg_type", msg_type);

                MysqlConnection mysqlcon = new MysqlConnection();
                mysqlcon.update_message_status(remote_id);

                sender_respondejson.put("remote_id", remote_id);
                sender_respondejson.put("msg_for", msg_for);
                sender_respondejson.put("msg_content", msg_content);
                sender_respondejson.put("msg_type", "3");

                jedis.publish(from + "", json.toString());
            }
        }
    } else if (msg_for.equals("1")) {
        //Chatroom message
        if (msg_content.equals("0")) {
            if (msg_type.equals("0")) {
                local_id = msgObject.getInt("local_id");
                from = msgObject.getInt("from");
                chatroomid = msgObject.getInt("chatroomid");
                to = chatroomid;
                msg = msgObject.getString("message");

                Date now = new Date();
                Long timestamp = new Long(now.getTime() / 1000);

                MysqlConnection mysqlcon = new MysqlConnection();
                String chatroomusersjson = mysqlcon.send_chatroom_message(message, timestamp, msg_content);

                json.put("from", from+"");
                json.put("message", msg);
                json.put("chatroomid", chatroomid+"");
                json.put("msg_for", msg_for);
                json.put("msg_content", msg_content);
                json.put("msg_type", msg_type);

                String key = "chatroom_" + chatroomid;
                String val = json.toString();

                jedis.rpush(key, val);

                JSONObject chatroomusersjsonobject = new JSONObject(chatroomusersjson);
                JSONArray chartoomusers = chatroomusersjsonobject.getJSONArray("chatroomusers");
                String lastchatroommessageid = chatroomusersjsonobject.getString("lastchatroommessageid");

                json.put("remote_id", lastchatroommessageid);

                sender_respondejson.put("local_id", local_id);
                sender_respondejson.put("remote_id", lastchatroommessageid);
                sender_respondejson.put("msg_for", msg_for);
                sender_respondejson.put("msg_content", msg_content);
                sender_respondejson.put("msg_type", "1");

                for (int i = 0; i < chartoomusers.length(); i++) {
                    to = chartoomusers.getInt(i);
                    jedis.publish(to + "", json.toString());
                }

                /*for(int i=0; i<500; i++){
                 jedis.publish(to + "", i+ " " + chatroomusersjson + " " +json.toString());
                 }*/
            }
        }
    } else if (msg_for.equals("2")) {
        //Group message
    }
    //}

    /*String[] temptp = topic.toString().split("Name: ");
     String[] temptp1 = temptp[1].split("AtmosphereResource:");
     String[] temptp2 = topic.toString().split(temptp1[0]);

     String newtopic = "Name: " + to + " " + temptp2[1];*/
    return new Broadcastable(sender_respondejson.toString(), "", topic);
}

}

谁能告诉我应该怎么做才能避免tomcat服务器崩溃。

4

1 回答 1

1

日志信息较少。请告诉我更多信息。

这类似于这个 SO 问题:“ No provider classes found: when running Jersey REST example application ”。

于 2013-10-16T14:42:37.360 回答