关于弱引用的问题(Issue about weakreferences)
我的程序中有一两个
weakreferences
。仅举例如:
ClassX myClassX= new ClassX(); //Line 1 WeakReference<ClassX> myWeakClassX = new WeakReference<ClassX>(myClassX); //Line 2 if(myWeakClassX.get() != null) // Line 3 { //do something with reference //Line 4 }
我的问题:
如何确保在第3行
myWeakClassX.get()
具有对Object
的有效引用时,它在第4行也有效? 我可以想象,如果你真的不走运,那么GC就完全“在”3号线和4号线之间完成他的工作。请耐心等待,因为我对Android / Java相对较新。谢谢你的任何解释。
I have one or two
weakreferences
in my program.Just for example:
ClassX myClassX= new ClassX(); //Line 1 WeakReference<ClassX> myWeakClassX = new WeakReference<ClassX>(myClassX); //Line 2 if(myWeakClassX.get() != null) // Line 3 { //do something with reference //Line 4 }
My question:
How is it ensured that when at line 3
myWeakClassX.get()
has a valid reference to anObject
, it is also valid at line 4? I can imagine that if you are really unlucky, the GC does his job exactly "between" line 3 and 4. Please bear with me, because i'm relatively new to Android/Java..Thanks for any explanation.
原文:https://stackoverflow.com/questions/27904627
最满意答案
要从当前目录运行程序,你应该使用
./
:./mysql
您也可以将它添加到PATH,然后您就可以从任何目录执行它:
mysql
to run a program from current directory you should use
./
:./mysql
You can also add it to the PATH, then you are able to execute it from any directory with:
mysql
相关问答
更多-
random.randint()不会在终端中运行,但可以在IDLE中运行(random.randint() won't run in Terminal but works in IDLE)[2022-12-10]
我发现了这个问题! 尽管我的脚本没有相互冲突的名称,但我有一个不同的脚本(我已经忘记了一个脚本),它被命名为“random.py”。 我的脚本试图在CLI中运行时导入,但IDLE导入了正确的脚本。 确保从不使用脚本名称的内置模块名称,即使您不在当前脚本中使用该模块。 它会在稍后造成问题! I found the issue! Although my script did not have a conflicting name, I had a different script (one I long for ... -
如果mysql位于/usr/local/mysql/bin而不是/usr/local/bin那么更新你的PATH : export PATH=$PATH:/usr/local/mysql/bin 在您的问题中,您在用户名前面有一个短划线,请尝试: mysql --user=phpuser --password=password < /path/to/file.sql If mysql is in /usr/local/mysql/bin rather than /usr/local/bin then u ...
-
我相信你可能只是错过了分号 create database test; I believe that you may just be missing the semicolon create database test;
-
您可能必须更新/etc/paths以包含MySQL二进制文件的位置。 对于OS X Lion,我的意思是添加/usr/local/mysql/bin 。 You might have to update /etc/paths to include the location of the MySQL binaries. For me on OS X Lion, that meant adding /usr/local/mysql/bin.
-
或者添加到你的.bashrc中: CDPATH="$CDPATH:$HOME/Documents/projects/personal/side_projects:$HOME/Documents/projects/personal/freelance" 你可以在任何地方使用cd project1 。 Or add this to your .bashrc: CDPATH="$CDPATH:$HOME/Documents/projects/personal/side_projects:$HOME/Docume ...
-
如何在applescript终端中更改带空格的目录?(How to change directory with spaces in applescript terminal?)[2023-04-06]
有几种方法。 # escape the quotes with a backslash. AND Escape the first backslash for Applescript to accept it. tell application "Terminal" activate do script "cd ~/Pictures/iPhoto\\ Library" end tell # surround in double quotes and escape the quotes wi ... -
我会建议像活动或同步这样的东西,但c/1 , l/1和nl/1简单方法也适用 I would suggest something like active or sync but straightforward approach with c/1, l/1 and nl/1 works too
-
删除了Anaconda目录,现在无法在终端中使用Python3(Deleted Anaconda directory, now can't use Python3 in Terminal)[2023-07-14]
Bash缓存名称查找; 清除该缓存中的python3 : hash -d python3 下次使用python3将再次搜索PATH目录,并再次缓存结果。 Bash caches name lookups; clear python3 from that cache: hash -d python3 The next time you use python3 the PATH directories are searched again and the result is cached again. -
要从当前目录运行程序,你应该使用./ : ./mysql 您也可以将它添加到PATH,然后您就可以从任何目录执行它: mysql to run a program from current directory you should use ./: ./mysql You can also add it to the PATH, then you are able to execute it from any directory with: mysql
-
为什么它显示PATH有结肠分隔符而不是分号分隔符? 因为bash使用:作为路径分隔符。 这意味着PATH环境变量中的C:/yadda/yadda被解析为两个目录: C和/yadda/yadda 。 如果仔细观察echo $PATH输出,您将看到许多条目以/c/开头。 python安装的条目是唯一使用C:/的条目。 在.bashrc或.profile中设置PATH时应使用/c/表示法。 还要注意路径名中的空格和前后的无关空格: 。 前者肯定是有问题的。 我不确定后者,因为在设置PATH时我从不在此位置添加空格 ...