i have a GUI application that needs to check that it is connected to a database every 30 - 60 secs. can this be done with java threads or do i need to look somewhere different. obviously i need the application to be fully useable whilst it is performing this.

Best use a Timer and TimerTask, that's what they're there for after all :)

Creating your own mechanism using threads (which a Timer no doubt uses under the hood) is certainly possible, but why do things the hard way?

Do mind that whatever option you choose there are no exact guarantees for the interval you want. What you'll actually get will depend on outside influences (operating system timeslicing etc.) but with a Timer the JVM will try what it can to get as close as it can, while with your own threads it will only guarantee a minimum sleep period.

cheers, thats really helped. i didnt actually know it existed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.