简体   繁体   English

如何使用Java从XML文件创建线程

[英]How to create threads from XML file using Java

I am new to Java and wanted to know if I have an xml file such as this: 我是Java新手,想知道我是否有这样的xml文件:

`<?xml version="1.0" encoding="UTF-8"?>
<Runners>
<Runner Name="Germany">
<RunnersMoveIncrement>70</RunnersMoveIncrement>
<RestPercentage>10</RestPercentage>
</Runner>
<Runner Name="US">
<RunnersMoveIncrement>10</RunnersMoveIncrement>
<RestPercentage>9</RestPercentage>
</Runner>
<Runner Name="UK">
<RunnersMoveIncrement>20</RunnersMoveIncrement>
    <RestPercentage>7</Restpercentage>
    </Runner>
    <Runner Name="CHINA">

<RunnersMoveIncrement>30</RunnersMoveIncrement>
<RestPercentage>15</RestPercentage>
</Runner>
</Runners>'

how do I read this and create threads for this xml file for each of the runner information using the attributes given ? 如何阅读本文并使用给定的属性为每个运行器信息为此xml文件创建线程? There are so many articles saying so many ways. 有太多文章说了这么多方法。 I am really confused what to do. 我真的很困惑该怎么办。 Can someone give me some idea what to do or a reference as to how to do this? 有人可以给我一些想法做什么或如何做的参考吗?

There is several solution to read XML file with Java but I think you have to make the search by yourself. 有几种使用Java读取XML文件的解决方案,但我认为您必须自己进行搜索。 Here comes some trails : 这里有一些线索:

According to me, a good programmer is curious ; 在我看来,一个好的程序员很好奇。 don't just ask a question and wait for an answer ;) 不要只是问一个问题并等待答案;)

A simple way to use threads is : 使用线程的一种简单方法是:

public class MyThread extends Thread {
    public void run() {
       // What you want to do here ...
    }
}

or ... 要么 ...

public class MyRunnable implements Runnable {
    public void run() {
       // What you want to do here ...
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM