簡體   English   中英

靜態方法調用單例

[英]static method calling singleton

考慮我在我繼承的應用程序中遇到的這種“模式”:

public class BusinessUtil{
    public static void doBusiness(IService myService, String arg1, int arg2){
        //something something
        myService.doStuff(arg1, arg2);
    }
}

bean is a springBean (=singleton). bean是一個springBean(= singleton)。 它實際上是一個cxf-client(=生成的webservice-client)

method is called from different concurrent threads. 這是一個web應用程序,因此從不同的並發線程調用靜態方法。 這個方法是線程安全的嗎?

在你問之前:我知道這是一種奇怪的“模式”。 method is quite redundant since we can call directly instead of passing it into a static method, where it is called. 我知道方法是多余的,因為我們可以直接調用而不是將其傳遞給靜態方法,在那里調用它。 正如我所說,我繼承了一個應用程序,其中“模式”到處都是。 我不知道為什么。 應用程序(有時)有一些奇怪的行為,我試圖找到問題的根源。

doBusiness()中沒有任何東西可以使它不安全。 是否是線程安全取決於myService.doStuff(arg1, arg2);線程安全性myService.doStuff(arg1, arg2);

它是否是線程安全的取決於myService.doStuff(arg1,arg2); 既然是cxf-client這篇文章是CXF客戶端代理線程安全嗎? 可能有用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM