I have a Java class that runs 2 separate threads. The first thread starts fine, and all the variables are correct.
When I start the second thread, the global variables from thread 1 change to the values set in thread 2.
I tried to add synchronized blocks where global variables are updated, but this did not work.
Is there any way to solve this problem? I want each thread to start and use its own values without interference in other values of the stream.
EDIT:
A snippet of my Thread class:
public abstract class ConsumerIF implements Runnable { public static Element root = null; public static String name = null; public static String type = null; public static String location = null; public final synchronized void reconfigure() throws FatalDistributionException { Document doc = builder.build(new StringReader(xmlCollector)); root = doc.getRootElement(); Element nameElement = root.getChild("name"); Element typeElement = root.getChild("type"); Element locationElement = root.getChild("location"); Element scheduleElement = root.getChild("schedule"); if (nameElement != null && typeElement != null && locationElement != null){ name = nameElement.getTextTrim(); type = typeElement.getTextTrim(); location = locationElement.getTextTrim(); } } }
lulu88
source share