我有和应用程序部署在tomcat中并且有很多线程忙着没有释放700多个像这样:
嗨,大家好!!我捕获了thead转储文件在ufile.io/8zz1t上,我使用fastthread.io来读取.你能检查一下你是否看到了问题,我看到inflater有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
Run Code Online (Sandbox Code Playgroud)
代码的哪一部分可能导致线程繁忙我不知道deflater或inflater是否必须关闭.
在应用程序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);
}
Run Code Online (Sandbox Code Playgroud)
}
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;
}
Run Code Online (Sandbox Code Playgroud)
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);
}
}
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
所有线程都位于inflater.inflate(buffer)SBCCypherModuleCompress.java 的第 92 行中。
但你为什么要写呢new byte['?']?这是在下面的代码中:
byte[] buffer = new byte['?'];
while (!deflater.finished())
{
int count = deflater.deflate(buffer);
outputStream.write(buffer, 0, count);
}
Run Code Online (Sandbox Code Playgroud)
以及以下代码:
byte[] buffer = new byte['?'];
while (!inflater.finished())
{
int count = inflater.inflate(buffer);
outputStream.write(buffer, 0, count);
}
Run Code Online (Sandbox Code Playgroud)
new byte['?']没有意义。
new byte[2048]或者也许new byte[8192]代替 会更好new byte['?']。
| 归档时间: |
|
| 查看次数: |
120 次 |
| 最近记录: |