我在文件中有如下几行
....... DisplayName="john" ..........
Run Code Online (Sandbox Code Playgroud)
其中....表示其他字段的可变数量。
使用以下 grep 命令,我能够提取具有有效“DisplayName”字段的所有行:
grep DisplayName="[0-9A-Za-z[:space:]]*" e:\test
Run Code Online (Sandbox Code Playgroud)
但是,我希望只从每一行中提取名称(即“john”),而不是从 grep 返回的整行中提取。我尝试将输出通过管道传输到cut命令中,但它不接受字符串分隔符。
当通过停放线程来暂停线程执行时,是否会导致线程放弃任何获取的对象监视器的所有权?
简而言之,如果一个线程 (t1) 获取“this”对象的监视器并被停放,而另一个线程 (t2) 通过首先尝试获取“this”的监视器并阻塞来尝试取消停放 t1,则以下代码是否会死锁。
// Thread t1 executes this code first.
syncronized(this) {
LockSupport.park();
}
// Thread t2 then executes this piece of code.
synchronized(this) {
LockSupport.unpark(t1);
}
Run Code Online (Sandbox Code Playgroud) java concurrency multithreading deadlock java.util.concurrent
我的面板上有一个 JComboBox。弹出菜单项之一是“更多”,当我单击它时,我会获取更多菜单项并将它们添加到现有列表中。在此之后,我希望保持弹出菜单打开,以便用户意识到已获取更多项目,但是弹出菜单关闭。我使用的事件处理程序代码如下
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == myCombo) {
JComboBox selectedBox = (JComboBox) e.getSource();
String item = (String) selectedBox.getSelectedItem();
if (item.toLowerCase().equals("more")) {
fetchItems(selectedBox);
}
selectedBox.showPopup();
selectedBox.setPopupVisible(true);
}
}
private void fetchItems(JComboBox box)
{
box.removeAllItems();
/* code to fetch items and store them in the Set<String> items */
for (String s : items) {
box.addItem(s);
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么 showPopup() 和 setPopupVisible() 方法没有按预期运行。
我想在启动Play应用程序时运行一些代码.这似乎不起作用.有线索吗?
public class Global extends GlobalSettings {
@Override
public void onStart(Application app) {
Logger.info("Foo Fee Fi");
}
}
Run Code Online (Sandbox Code Playgroud)