Okay, this puzzle the hell out of me.
I've got 2 different sets of code, one which works, one which doesn't. They are both very similar, and I can't see what is causing the problem.
Code that works:
public static void main(String[] args) {
PropertyConfigurator.configure("log4j.properties");
new Settings().globalSettings(args[0]);
logger.info("Read settings from " + args[0]);
while (true) {
logger.info("Starting main scanning loop.");
/*
* Get a list of jobs, then iterate through them, get their settings,
* and pick up files for them to process.
*
* Assumptions:
* 1. There are jobs in the settings file
*/
String[] jobList = new Settings().jobList(args[0]);
logger.info("Job found");
for (int numJobs = 0; numJobs < jobList.length; numJobs++) {
/*
* Get each job's settigns, then call filePickup() for it
*/
String jobName = jobList[numJobs];
new Settings().jobSettings(args[0], jobName);
logger.info("Starting job " + jobName);
try {
Thread.sleep(6000);
} catch (InterruptedException ie) {
}
new MultiThreader().scan();
}
}
}
void scan() {
/*
* This function makes it possible to track the total amount of threads
*/
if (!MultiThreader.priorityDirs.equals("") && !MultiThreader.priorityDirs.equals(null)) {
logger.info("Scanning high priority files");
/*
* Scan priority folder for files, use filepickup
* filePickup will scan the high priority dir(s)
*/
filePickup("high", MultiThreader.priorityThreads);
} else {
MultiThreader.normalThreads = MultiThreader.totalThreads;
}
if (!MultiThreader.normalDirs.equals("") && !MultiThreader.normalDirs.equals(null)) {
logger.info("Scanning low priority files");
/*
* Scan normal folders for files, use filepickup
* filepickup will scan the low priority dir(s)
*/
filePickup("low", MultiThreader.normalThreads);
}
}
Code that doesn't work:
public static void main(String[] args) {
PropertyConfigurator.configure("log4j.properties");
new Settings().globalSettings(args[0]);
logger.info("Read settings from " + args[0]);
while (true) {
logger.info("Starting main scanning loop.");
/*
* Get a list of jobs, then iterate through them, get their settings,
* and pick up files for them to process.
*
* Assumptions:
* 1. There are jobs in the settings file
*/
String[] jobList = new Settings().jobList(args[0]);
logger.info("Job found");
for (int numJobs = 0; numJobs < jobList.length; numJobs++) {
/*
* Get each job's settigns, then call filePickup() for it
*/
String jobName = jobList[numJobs];
new Settings().jobSettings(args[0], jobName);
logger.info("Starting job " + jobName);
try {
Thread.sleep(6000);
} catch (InterruptedException ie) {
}
new MultiThreader().jobSpawner(this, jobName); [B]// Error on this line[/B]
}
}
}
void jobSpawner(MultiThreader mt, String jobName) {
new Thread(new JobThread(mt, jobName)).start();
}
The error is "java.lang.RuntimeException: Uncompilable source code - non-static variable this cannot be referenced from a static context"
Please help me out here, this is extremely frustrating.