Q1. What is the best way to implement the singleton pattern using groovy? What are the other options available in groovy to support the singleton mechanism?
Any example that would be useful.
Q2. Does groovy support something like File changed listener?
You can make any class a singleton simply by adding a @Singleton annotation (since groovy v1.7.0 at least):
@Singleton
class MyClass {
}
You can then access the singleton instance with
MyClass singleton = MyClass.instance
I think you're asking if Groovy provides a listener which is called every time a file is changed? I am not aware of any such facility in Groovy. If such a class exists you're more likely to find a Java implementation (which you could use in your Groovy program).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With