简体   繁体   English

“ Singleton Session Bean”,用于存储应用程序范围的信息Java EE 6

[英]“Singleton Session Bean” to store application wide informations Java EE 6

I write a Java ee 6 application on a jboss-as-7 application server. 我在jboss-as-7应用程序服务器上编写了Java ee 6应用程序。 I want to have a “Singleton Session Bean” to store application wide informations in a list “mediaDataList”. 我想要一个“ Singleton Session Bean”,用于将应用程序范围的信息存储在“ mediaDataList”列表中。

A statless session bean “ClassA“ write some object to this list and a webservice reads the informations in the “mediaDataList” list. 无状态会话bean“ ClassA”将一些对象写入此列表,然后Web服务将读取“ mediaDataList”列表中的信息。

@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
@Lock(LockType.WRITE)
public class MediaDataSafe {

    private final List<MediaData> mediaDataList = new ArrayList<MediaData>();

    @Inject
    Logger log;

    @PostConstruct
    void init() {
        // read from HD and store in mediaDataList
    }


    // just read the list...
    public List<MediaData> getMediaDataList() {
        return mediaDataList;
    }

    // write to list
    public void writeMediaDataSafe(...) {
        mediaDataList.add(auraMediaData);
    }
}


@Stateless
public class ClassA {

    @Inject
    MediaDataSafe mediaDataSafe;

    //write in list of singleton
    public void write(...) {
        mediaDataSafe.writeMediaDataSafe(...);
    }
}

@WebService(serviceName = "MyWebService", endpointInterface = "com.WebService")
public class MyWebService implements com.bla.WebService {

    //...

    @Inject
    transient MediaDataSafe mediaDataSafe;

    //read from list in singleton
    public MediaList getMediaList(...){
        mediaDataSafe.getMediaDataList(...);
    }
}

My problem is, it seems that there exists two “signleton bean” in my system! 我的问题是,我的系统中似乎存在两个“ signleton bean”! If “ClassA “ write some new values to the list, I can't read this new values with my webservice. 如果“ ClassA”将一些新值写入列表,则我的Web服务无法读取此新值。 The webservice returns always the same list. Web服务始终返回相同的列表。 (it contains the state on init!) (它包含init上的状态!)

What do I wrong? 我怎么了 Do I misunderstanding something here about “Singleton Session Bean”? 我在这里对“ Singleton Session Bean”有误解吗?

It looks fine so far for me, since a Singleton is instantiated once per application, the only reasons I can think of leading possibly to the described behaviour is something in the direction of several deployments of the same application. 到目前为止,对我来说看起来还不错,因为每个应用程序实例化了一个Singleton,所以我想到可能导致所描述行为的唯一原因是朝着同一应用程序的多个部署方向发展。

Maybe it helps to read the following parts of the Java EE 6 tutorial carefully to find the problem: 仔细阅读Java EE 6教程的以下部分以发现问题可能会有所帮助:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM