Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why are providers instantiated multiple times by AudioSystem / MidiSystem?

instantiated times
0
10 Posted

Why are providers instantiated multiple times by AudioSystem / MidiSystem?

0
10

In JDK versions up to 1.4.2, each time AudioSystem or MidiSystem needs a list of providers, it calls sun.misc.Service.providers(), which reads the configuration files, and returns an Enumeration object, than, when used, instantiates the providers (lazy instantiation). In the JDK 1.5, a cacheing mechanism was introduced. The lists of providers are instantiated completely and cached for 60 seconds. The recommended way to deal with multiple instantiations of MixerProvider and MidiDeviceProvider subclasses is is to implement some type of singleton behaviour. For instance, information gathered at instantiation could be stored in static members, and the initialisation guarded by a flag. The other types of providers (AudioFileReader, AudioFileWriter, FormatConversionProvider, MidiFileReader, MidiFileWriter, SoundbankReader) are typically so simple that the constructor is empty anyway.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123