能否请您澄清代码有什么问题:
问:即使我没有将blinker声明为volatile,但是线程t1能够看到主线程设置的更新值(true)....
码:
package com.learning;
public class HowToStopRunningThread implements Runnable{
/**
* @param args
*/
public static boolean blinker;
public static void main(String[] args) {
Thread t = new Thread(new HowToStopRunningThread());
t.start();
HowToStopRunningThread obj = new HowToStopRunningThread();
obj.stop();
}
public void stop(){
try{
Thread.sleep(100);
System.out.println(“Setting the Blinker value”);
blinker = true;
}catch(InterruptedException ie){
ie.getMessage();
}
}
@Override
public void run() {
while(!blinker){
try{
System.out.println(“blinker:”+blinker);
Thread.sleep(1000);
}catch(InterruptedException ie){
ie.getMessage();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
blinker:false
Setting the Blinker value
Run Code Online (Sandbox Code Playgroud)
-----------然后线程从while循环中出来
我正在使用Enrich Mediator丰富的XML.
我的问题是,它总是适用于第一个元素,虽然我想将它应用于多个元素.如何将其应用于XPATH选择的所有元素?
我也试过下面的选项.但失败了.
//Response/ResponseDetails/SearchHotelPriceResponse/HotelDetails/Hotel[@HasExtraInfo="true"]
Run Code Online (Sandbox Code Playgroud)
丰富配置:
<enrich>
<source type="inline">
<ImageCode xmlns="">IMG10004</ImageCode>
</source>
<target action="child" xpath="//Response/ResponseDetails/SearchHotelPriceResponse/HotelDetails/Hotel[*]"/>
</enrich>
Run Code Online (Sandbox Code Playgroud)
XML有效负载:
<Response ResponseReference="REF_D_028_749-2801486459143247">
<ResponseDetails Language="en">
<SearchHotelPriceResponse>
<HotelDetails>
<Hotel HasExtraInfo="true" HasMap="true" HasPictures="true">
<City Code="LON">London</City>
<Item Code="ALE1">ALEXANDRA</Item>
<StarRating>3</StarRating>
<HotelRooms>
<HotelRoom Code="SB" NumberOfRooms="1"/>
</HotelRooms>
</Hotel>
<Hotel HasExtraInfo="true" HasPictures="true">
<City Code="LON">London</City>
<Item Code="ALO">Aloft London Excel</Item>
<StarRating>4</StarRating>
<HotelRooms>
<HotelRoom Code="SB" NumberOfRooms="1"/>
</HotelRooms>
</Hotel>
<Hotel HasExtraInfo="true" HasMap="true" HasPictures="true">
<City Code="LON">London</City>
<Item Code="AMB3">Ambassadors Bloomsbury</Item>
<StarRating>4</StarRating>
<HotelRooms>
<HotelRoom Code="SB" NumberOfRooms="1"/>
</HotelRooms>
</Hotel>
</HotelDetails>
</SearchHotelPriceResponse>
</ResponseDetails>
</Response>
Run Code Online (Sandbox Code Playgroud)
我最近一直在阅读单身人士,我常常看到如下代码:
private static SingletonDemo instance = null;
Run Code Online (Sandbox Code Playgroud)
在Singleton类中作为一个字段.
我不想特别了解'静态'在做什么以及为什么需要它.
我在这里阅读了Oracle网站.并且他们使用a numOfBicycles(这是你有多个自行车的时候)的例子来证明使用静态字段,但我认为我正在理解为什么在你只是实例化1个实例时使用它.
我认为这样做arraylist1=arraylist2可以使其中的2个共享相同的内存.如果没有他们这样做,我怎么能复制一个arraylist?我想把它们分开对待.
List<Integer> rez = new ArrayList<>();
List<Integer> rezc = new ArrayList<>();
rez.add(1);
rezc=rez;
rezc.add(2);
for (int s : rez) {
System.out.print(s + " ");
}//this will print 1 2
Run Code Online (Sandbox Code Playgroud)