小编Abi*_*san的帖子

线程能够看到java中主线程设置的更新静态变量

能否请您澄清代码有什么问题:

问:即使我没有将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循环中出来

java static multithreading volatile

0
推荐指数
1
解决办法
217
查看次数

Enrich Mediator仅适用于WSO2 ESB 5中的First元素

我正在使用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)
  • ESB版本5.0.0

xml xpath wso2 wso2esb

0
推荐指数
1
解决办法
422
查看次数

为什么静态字段用于单例?

我最近一直在阅读单身人士,我常常看到如下代码:

private static SingletonDemo instance = null;
Run Code Online (Sandbox Code Playgroud)

在Singleton类中作为一个字段.

我不想特别了解'静态'在做什么以及为什么需要它.

我在这里阅读了Oracle网站.并且他们使用a numOfBicycles(这是你有多个自行车的时候)的例子来证明使用静态字段,但我认为我正在理解为什么在你只是实例化1个实例时使用它.

singleton design-patterns

-2
推荐指数
1
解决办法
704
查看次数

复制arraylist

我认为这样做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)

java arraylist

-3
推荐指数
1
解决办法
115
查看次数