gpt4 book ai didi

java - PMD 消息 "Avoid using java.lang.ThreadGroup; it is not thread safe"

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:42:15 24 4
gpt4 key购买 nike

问题:

为什么 maven PMD 插件对下面的代码行发出以下警告:警告:

Avoid using java.lang.ThreadGroup; it is not thread safe

代码(第二行):

Calendar cal = Calendar.getInstance();
java.sql.Date endDate = new java.sql.Date(cal.getTime().getTime());

上下文:

我有一个 java.sql.Date 实例:

public class XYZServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doPost(req, resp);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse resp)
throws ServletException, IOException {


Connection conn = null;
CallableStatement stmt = null;
try {
conn = ...
...

Calendar cal = Calendar.getInstance();
java.sql.Date endDate = new java.sql.Date(cal.getTime().getTime());

...
} catch ...
}finally {
try {
stmt.close();
conn.close();
} catch(Exception e) {}
}
}

PMD报告的行是

java.sql.Date endDate = new java.sql.Date(cal.getTime().getTime());

消息是:

Avoid using java.lang.ThreadGroup; it is not thread safe

最佳答案

这似乎是 PMD 4.2.6 中的错误。

SourceForge-链接:
http://sourceforge.net/projects/pmd/forums/forum/188192/topic/4781145

关于java - PMD 消息 "Avoid using java.lang.ThreadGroup; it is not thread safe",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9771674/

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