Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想检查在 Struts 1 Action 类中具有同步实例方法意味着什么?
就像是
public synchronized String checkAction(){ ... }
这意味着 checkAction 方法将被封闭对象的内在锁(动作类对象的锁)同步。因此,一次只有一个线程能够访问 checkAction 方法。
在 Struts 1 中,Action 类不是线程安全的。所以多个线程(例如服务多个请求)将访问 Action 类的同一个实例。方法是否需要同步?我不确定——只有你可以通过方法中发生的事情来判断。只要它不访问 Action 类的实例变量或执行一次只能由单个线程完成的事情,那么同步可能就没有必要了。