gpt4 book ai didi

java - Memcached ClassNotFound 异常

转载 作者:行者123 更新时间:2023-12-01 14:16:41 27 4
gpt4 key购买 nike

所以我想我对 memcached 的工作原理有点困惑。我正在使用不同的框架开发相同的API,所有这些框架都包含memcached(java版本的spymemcached)。当我在第一个框架上设置 memcached 时,它按预期工作。现在,我尝试将其合并到我正在使用的第二个框架中,但我不断收到 ClassNotFoundException 异常,它试图在我使用的第一个框架中查找类,因此不会缓存任何内容。也许有人可以启发我发现我的逻辑缺陷。这是两个类(它们是相同的,因为我在不同的平台上构建相同的 API),core.Party 类位于第一个类中(在运行相应的应用程序时起作用) pojo.PojoParty 是我使用的第一个也是第二个框架,它似乎没有连接到内存缓存。

这是它发生的类的构造函数:

    package resources;

import health.TemplateHealthCheck;

import java.net.InetSocketAddress;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.ResultSetMetaData;
import java.util.HashMap;

import com.codahale.metrics.Gauge;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Counter;
import com.codahale.metrics.RatioGauge;

import contextListener.MyAdminServletContextListener;

import pojo.PartyPojo;

import net.spy.memcached.MemcachedClient;

public class DBConnection {

public static Connection con;
private static ResultSet resultSet;
private static PreparedStatement ps;
private static ResultSetMetaData meta;
private static HashMap<String,PartyPojo> map;
private static DBConnection connection;
private static PartyPojo party;
private static final InetSocketAddress isa= new InetSocketAddress("atom1.cisco.com",11211);
private static MemcachedClient memcache;
private static Meter hits = MyAdminServletContextListener.registry.meter(MetricRegistry.name("Meter",
"get-hits"));
private static Meter calls = MyAdminServletContextListener.registry.meter(MetricRegistry.name("Meter",
"get-calls"));
private static Counter evictions = MyAdminServletContextListener.registry.counter(MetricRegistry.name("Counter",
"Memcache-Evictions"));
private static int getHits,getCalls;
private final static int MAX_MEMCACHED_EXPIRATION=2505600;

private DBConnection()
{
try
{
map = new HashMap<String,PartyPojo>();
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(
"jdbc:mysql://atom3.cisco.com:3306/reddb", "redteam",
"redteam");
//initialize memcache
memcache = new MemcachedClient(isa); //this line produces error
//this is just a integer variable I was using to make sure my Meters were measuring correctly
getHits = Integer.valueOf(DBConnection.memcache.getStats().get(DBConnection.isa).
get("get_hits"));
getCalls = Integer.valueOf(DBConnection.memcache.getStats().get(DBConnection.isa).
get("cmd_get"));
metricsRegistry();
}
catch (Exception e)
{
e.printStackTrace();
}
}

这是它试图访问的类,它不属于第二个框架(这是第一个框架中的 pojo 类):

    package core;

import java.io.Serializable;
import java.util.HashMap;

public class Party implements Serializable {


/**
*
*/
private static final long serialVersionUID = 1L;
HashMap <String,String> partyInfo = new HashMap<String,String>();

public HashMap<String,String> getPartyInfo() throws Exception
{
return partyInfo;
}
}

这是相同的类,但在我尝试运行的项目中

    package pojo;

import java.io.Serializable;
import java.util.HashMap;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.eclipse.persistence.oxm.annotations.XmlPath;


@XmlRootElement(name="Party")
@XmlAccessorType(XmlAccessType.FIELD)
public class PartyPojo implements Serializable {

/**
*
*/
private static final long serialVersionUID = -4892745279086305480L;
/**
*
*/
/**
*
*/
@XmlPath(".")
@XmlJavaTypeAdapter(MapAdapter.class)

HashMap <String,String> partyInfo = new HashMap<String,String>();

public HashMap<String,String> getPartyInfo() throws Exception
{
return partyInfo;
}
}

这是堆栈跟踪:

 2013-08-05 15:54:39.810 INFO net.spy.memcached.MemcachedConnection:  Added {QA sa=atom1.cisco.com/173.36.62.251:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2013-08-05 15:54:39.847 INFO net.spy.memcached.MemcachedConnection: Connection state changed for sun.nio.ch.SelectionKeyImpl@529762a
2013-08-05 15:54:40.120 WARN net.spy.memcached.transcoders.SerializingTranscoder: Caught CNFE decoding 434 bytes of data
java.lang.ClassNotFoundException: core.Party
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at java.io.ObjectInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at net.spy.memcached.transcoders.BaseSerializingTranscoder.deserialize(BaseSerializingTranscoder.java:129)
at net.spy.memcached.transcoders.SerializingTranscoder.decode(SerializingTranscoder.java:88)
at net.spy.memcached.transcoders.TranscodeService$1.call(TranscodeService.java:63)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at net.spy.memcached.transcoders.TranscodeService$Task.run(TranscodeService.java:110)
at net.spy.memcached.transcoders.TranscodeService$Task.get(TranscodeService.java:96)
at net.spy.memcached.internal.GetFuture.get(GetFuture.java:63)
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:997)
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1018)
at resources.DBConnection.readOneParty(DBConnection.java:114)
at resources.OnePartyResource.getParty(OnePartyResource.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
at com.sun.jersey.server.impl.uri.rules.SubLocatorRule.accept(SubLocatorRule.java:134)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:211)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1094)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:445)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:267)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:224)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
at java.lang.Thread.run(Unknown Source)

最佳答案

我想通了,答案很尴尬。因此,因为我急于完成不同框架上的代码,所以我基本上将代码从一个框架复制并粘贴到另一个框架上。本质上发生的事情是它存储来自第一个 API 的值;但是,当我尝试使用其他 API 查询这些相同的值时,它试图将这些值存储在内存缓存中的同一关键位置。因此为什么它找不到该对象,它位于错误的项目中!因此,我基本上为一个程序附加了字符串键,以便它能够正确返回。

这显然是一个令人尴尬的错误,但我将其归结为我第一次跨多个程序使用任何类型的缓存系统。

关于java - Memcached ClassNotFound 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18067847/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com