GroupMemberServiceImpl:
Thread thread = new Thread(() -> {
if (!(existingMember == null)) {
if (!(this.groupMembersDAO.checkIfMemberAlreadyExists(existingMember.getUsername(), groupId))) {
members.setMemberUsername(members.getMemberUsername().toLowerCase());
members.setMemberactivated(true);
createToken(existingMember.getFirstName(),members.getMemberUsername(), members.isAccesslevel(), groupId);
WaitingMembers waitingMembers = new WaitingMembers();
waitingMembers.setGroupAccountId(groupId);
waitingMembers.setMemberEmail(members.getMemberUsername());
waitingMembers.setNickName(nickName);
this.waitingMembersService.addMemberInWaiting(waitingMembers);
}
} else {
GroupAccount groupAccount = this.groupAccountService.getGroupById(groupId);
WaitingMembers waitingMembers = new WaitingMembers();
waitingMembers.setGroupAccountId(groupId);
waitingMembers.setMemberEmail(members.getMemberUsername());
waitingMembers.setNickName(nickName);
this.waitingMembersService.addMemberInWaiting(waitingMembers);
Person inviter = this.personService.findPersonByUsername(groupAccount.getAdminUsername());
sendFirstTimeGroupUserAccountActivationEmail(nickName, members, inviter.getFirstName(), groupAccount.getGroupName(), groupId);
}
});
thread.start();
我使用线程的方式有问题吗?有任何复杂的方法可以防止这个问题吗?
我在生产中使用https,压缩和缓存。
生产中的Server.xml:
<Connector port="80" protocol="HTTP/1.1" compression="force" compressionMinSize="1024"
connectionTimeout="20000"
redirectPort="443" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"/>
<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="200" compression="force"
compressionMinSize="1024" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS"
keystoreFile="/etc/ssl/private/my-keystore.jks" keystorePass="password" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"
/>
任何帮助都会很好。非常感谢。
答案 0 :(得分:0)
最好为spring定义ThreadPoolTaskExecutor。像这样。从here获取代码段。该方法允许控制线程的数量同时工作。
ThreadPoolTaskExecutor taskExecutor = (ThreadPoolTaskExecutor) context.getBean("taskExecutor");
PrintTask2 printTask1 = (PrintTask2) context.getBean("printTask2");
printTask1.setName("Thread 1");
taskExecutor.execute(printTask1);
关于你的第二个问题。简短的回答是 - 是的