Question about a class implementing Runnable
Hello everyone
I made an application using a custom PropertiesFile class which i made implement Runnable. Here it is in its entirety:
Code:
package Utils;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
public class PropertiesFile implements Runnable
{
private static Properties props;
@Override
public void run()
{
try
{
props = new Properties();
FileInputStream fis = new FileInputStream("config/config.ini");
props.load(fis);
fis.close();
Logs.getPropsLog().log(Level.INFO, "Successfully loaded properties file");
}
catch(IOException ex)
{
Logs.getPropsLog().log(Level.SEVERE, "Unable to load properties file : " + ex.getMessage(), ex);
}
}
public static String getProperty(String name)
{
String propValue = props.getProperty(name);
Logs.getPropsLog().log(Level.INFO, "Reading " + name + " property and returning " + propValue);
return propValue;
}
public static void setProperty(String name, String value)
{
props.setProperty(name, value);
try
{
props.store(new FileOutputStream("config/config.ini"), null);
}
catch (Exception ex)
{
}
}
}
I initialize it using :
Code:
new PropertiesFile().run();
My question is this : Will this class continuously run in its own thread? When i call getProperty(), does it stay in its thread? If not, how would i accomplish this. You might ask why do this with a simple config access class but i'm also doing it with my database handler, hibernate util, data access objects, etc and that was the shortest one :).
Thanks!
Martin