PHP头条
热点:

多线程-php单例问题疑问求解答


多线程phpsingleton

A.php

B.php

arg = $arg;  }  public function run(){    if($this->arg){      Singleton::GetInstance();    }  }}$arr = array();for($i=0;$i<10;$i++){    $arr[] = new AsyncOperation($i);}for($i=0;$i<10;$i++){    $arr[$i]->start();}

本人写java的 看到php的单例如A.php表示,但是实际在pthreads扩展下多线程跑的时候,会打印出内容,多次构造该实例。求各位phper解答疑问

对java熟悉点,java中

public class Singleton{    private static Object instance = null;    public Object getInstance(){        if(instance==null){            synchronized(Singleton.class){                if(instance==null){                    instance = new Singleton();                }            }        }        return instance    }}

www.phpzy.comtrue/phpyy/3335.htmlTechArticle多线程-php单例问题疑问求解答 多线程phpsingleton A.php B.php arg = $arg; } public function run(){ if($this->arg){ Singleton::GetInstance(); } }}$arr = array();for($i=0;$i start();} 本人写java的 看到php的单例如A.php表示...

相关文章

相关频道:

PHP之友评论

今天推荐