我已经在Tomcat中部署了应用程序,并且有很多线程在忙,而没有发布超过700个这样的主题:
嗨,大家好!我捕获了Thead转储文件,文件位于ufile.io/8zz1t上,我使用fastthread.io进行读取。您能否检查是否看到问题,我发现充气机的CPU消耗了线程。
S 188063346 ms 0 KB 0 KB 10.162.3.36 172.30.100.163 POST /ChiperService/rest/cs/Descifrar HTTP/1.1
S 280064346 ms 0 KB 0 KB 10.162.3.36 172.30.100.163 POST /ChiperService/rest/cs/Descifrar HTTP/1.1
S 185431144 ms 0 KB 0 KB 10.162.38.201 172.30.100.163 POST /ChiperService/rest/cs/Descifrar HTTP/1.1
S 267094596 ms 0 KB 0 KB 10.162.3.36 172.30.100.163 POST /ChiperService/rest/cs/Descifrar HTTP/1.1
S 261396699 ms 0 KB 0 KB 10.162.3.36 172.30.100.163 POST /ChiperService/rest/cs/Descifrar HTTP/1.1
代码后面的哪一部分可能导致线程繁忙,我不知道放气机或充气机是否必须关闭。
在应用ChiperService的tomcat管理器中,没有活动的会话。
请帮助服务器一天崩溃近5次,因为thead忙并且cpu消耗高。
这是休息服务:
其他服务:
package ChiperServicePkg;
import com.sun.jersey.api.core.ResourceConfig;
import java.io.IOException;
import javax.ws.rs.core.Context;
import javax.ws.rs.POST;
import javax.ws.rs.PathParam;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import principal.allus.com.co.SBCCypherModuleMain;
/**
* REST Web Service
*
* @author 1017200731
*/
@Path("/cs")
public class CiphersResource {
@Context ResourceConfig Config;
/**
* Creates a new instance of CiphersResource
*/
public CiphersResource() {
}
/**
*
* @param UUI
* @return
* @throws Exception
*/
@POST
@Path("Cifrar")
public String Cifrar(String UUI) throws Exception
{
String Key = (String) Config.getProperty("KeyCipher");
String dataEncrypted = null;
try
{
dataEncrypted= SBCCypherModuleMain.cifrar(UUI,Key );
}
catch(Exception ex)
{
if (ex instanceof IOException){
throw new IOException(ex);
}
else{
throw ex;
}
}
return dataEncrypted;
}
/**
*
* @param dataEncrypted
* @return
* @throws Exception
*/
@POST
@Path("Descifrar")
public Response Descifrar(String dataEncrypted) throws Exception
{
String Key = (String) Config.getProperty("KeyCipher");
String dataDecrypted= "";
try
{
dataDecrypted= SBCCypherModuleMain.descifrar(dataEncrypted, Key);
}
catch(Exception ex)
{
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(ex.getMessage()).type("text/plain").build();
}
return Response.ok(dataDecrypted).build();
}
/**
* Sub-resource locator method for {id}
*/
@Path("{id}")
public CipherResource getCipherResource(@PathParam("id") String id) {
return CipherResource.getInstance(id);
}
}
方法Descifrar调用客户端提供的jar,并使用反编译器提取以下代码:
public static String descifrar(String bytes, String llave)
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, Exception
{
byte[] vector = null;
String retorno = "";
retorno = SBCCypherModuleCompress.descomprimir(SBCCypherModuleCypher.descifrar(bytes, llave.substring(0, 16)));
return retorno;
}
SBCCypherModuleCompress类如下:
public class SBCCypherModuleCompress
{
public static String comprimir(byte[] data)
throws IOException, Exception
{
BASE64Encoder b64e = new BASE64Encoder();
byte[] output = null;
String salida = "";
Deflater deflater = new Deflater();
deflater.setInput(data);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
deflater.finish();
byte[] buffer = new byte['?'];
while (!deflater.finished())
{
int count = deflater.deflate(buffer);
outputStream.write(buffer, 0, count);
}
outputStream.close();
output = outputStream.toByteArray();
salida = b64e.encode(output);
return salida;
}
public static String descomprimir(String data)
throws DataFormatException, IOException, Exception
{
BASE64Encoder b64e = new BASE64Encoder();
BASE64Decoder b64d = new BASE64Decoder();
byte[] output = null;
String salida = "";
byte[] datad = null;
datad = b64d.decodeBuffer(data);
Inflater inflater = new Inflater();
inflater.setInput(datad);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(datad.length);
byte[] buffer = new byte['?'];
while (!inflater.finished())
{
int count = inflater.inflate(buffer);
outputStream.write(buffer, 0, count);
}
outputStream.close();
output = outputStream.toByteArray();
salida = b64e.encode(output);
return new String(output);
}
}
SBCCypherModuleCypher类如下:
public class SBCCypherModuleCypher
{
public static String cifrar(String vector, String llaveSimetrica)
throws NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, Exception
{
BASE64Encoder b64e = new BASE64Encoder();
BASE64Decoder b64d = new BASE64Decoder();
byte[] datad = null;
String salida = "";
datad = b64d.decodeBuffer(vector);
SecretKeySpec key = new SecretKeySpec(llaveSimetrica.getBytes(), "AES");
byte[] campoCifrado = null;
Cipher cipher = Cipher.getInstance("AES");
cipher.init(1, key);
campoCifrado = cipher.doFinal(datad);
salida = b64e.encode(campoCifrado);
return salida;
}
public static String descifrar(String vector, String llaveSimetrica)
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, Exception
{
BASE64Encoder b64e = new BASE64Encoder();
BASE64Decoder b64d = new BASE64Decoder();
byte[] datad = null;
String salida = "";
datad = b64d.decodeBuffer(vector);
SecretKeySpec key = new SecretKeySpec(llaveSimetrica.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(2, key);
byte[] datosDecifrados = cipher.doFinal(datad);
salida = b64e.encode(datosDecifrados);
return salida;
}
}
答案 0 :(得分:1)
您所有的线程都位于SBCCypherModuleCompress.java第92行的inflater.inflate(buffer)
中。
但是您为什么写new byte['?']
?在以下代码中:
byte[] buffer = new byte['?'];
while (!deflater.finished())
{
int count = deflater.deflate(buffer);
outputStream.write(buffer, 0, count);
}
以及以下代码:
byte[] buffer = new byte['?'];
while (!inflater.finished())
{
int count = inflater.inflate(buffer);
outputStream.write(buffer, 0, count);
}
new byte['?']
毫无意义。
new byte[2048]
或new byte[8192]
可能比new byte['?']
更好。