我在线程A上有一个对象正在调用,wait()而线程B上的另一个对象做了一些工作,然后调用线程A的对象notify().线程A然后执行一些后处理.
我的问题很简单:
synchronized(this)
{
while(!flag)
{
try
{
wait();
getLogger().info("No longer waiting");
}
catch (InterruptedException ie)
{
getLogger().info("Wait threw InterruptedException");
}
}
}
Run Code Online (Sandbox Code Playgroud)
导致信息消息"不再等待"而不是"等待中断异常".
我很困惑,因为这个(http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html#wait()):
抛出:
InterruptedException - 如果另一个线程在当前线程等待通知之前或当前线程中断当前线程.抛出此异常时,将清除当前线程的中断状态.
为什么我会出现奇怪的行为?
谢谢.
Path和Paths之间的交互似乎很简单.使用Paths get()方法获取Path对象.然后,您可以使用Path的方法:
Path p = Paths.get("C:\\directory\\filename.txt");
p.getFilename();
p.getRoot();
p.getParent();
etc...
Run Code Online (Sandbox Code Playgroud)
令我困惑的是,Java文档将Path描述为一个接口.通常来说,接口只是方法签名的集合,您需要在任何声明它通过implements关键字使用它的类中实现它们.
但是,在Path的情况下,没有使用"implements"关键字,也没有实现这些方法.他们已经预定义了.
我显然在某个地方得到了错误的结局.有人可以解释一下我误解了什么吗?
我有一个ruby应用程序,我发送的文件http://ruby-doc.org/stdlib-2.0/libdoc/net/smtp/rdoc/Net/SMTP.html中提供了这种格式的电子邮件:
Net::SMTP.start('your.smtp.server', 25) do |smtp|
smtp.send_message msgstr, 'from@address', 'to@address'
end
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
def send_notification(exception)
msgstr = <<-END_OF_MESSAGE
From: Exchange Errors <exchangeerrors@5112.mysite.com>
To: Edmund Mai <emai@mysite.com>
Subject: test message
Date: Sat, 23 Jun 2001 16:26:43 +0900
Message-Id: <unique.message.id.string@mysite.com>
This is a test message.
END_OF_MESSAGE
Net::SMTP.start('localhost', 25) do |smtp|
smtp.send_message(msgstr, "exchangeerrors@5112.mysite.com", "emai@mysite.com")
end
end
Run Code Online (Sandbox Code Playgroud)
但是,发送的电子邮件中没有主题.在msgstr刚刚成为电子邮件的正文.我没有在文档中看到有关如何指定邮件主题的任何内容.有人知道吗?
我想在eclipse中用java画一条线。我制作了这段代码,但出现错误:paint2d.add(paintComponent());
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Game extends JPanel {
public void paintComponent (Graphics2D g) {
Graphics2D g2 = (Graphics2D) g;
g2.drawLine(30, 40, 80, 100);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(400, 420);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Game paint2d = new Game();
paint2d.add(paintComponent()); // The method paintComponent(Graphics2D) in the type Game is not applicable for the arguments ()
frame.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)
如何修复该错误?
我的代码适合画线吗?
谢谢。
我正在尝试使用 .python 文件读取文件并将数据插入到 python 中的 postgresql 表中psycopg2。
这是我写的函数:
def insert(file, table, col, conn):
sql = "INSERT INTO "+table+"("+col+") VALUES(%s)"
cur = conn.cursor()
with open(os.path.join(DEFAULTS_FOLDER, file)) as fp:
line = fp.readline()
while line:
cur.execute(sql, (line.rstrip(),))
line = fp.readline()
conn.commit()
cur.close()
return
Run Code Online (Sandbox Code Playgroud)
由于某种原因,我收到错误:
cur.execute(sql, (line.rstrip(),)) psycopg2.DataError: malformed array literal: "hello" LINE 1: INSERT INTO greetings(gname) VALUES('hello')
Run Code Online (Sandbox Code Playgroud)
我还尝试插入一个纯字符串,但仍然遇到相同的错误。
我正在尝试在Windows 7上的任务计划程序上配置任务.这是一个非常简单的 - 运行谷歌Chrome与一个论点,假设用Chrome打开一个网站.
命令是:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" google.com
Run Code Online (Sandbox Code Playgroud)
它的工作原理完全罚款从cmd和从batch file.
但到目前为止,我无法将其设置为在任务计划程序上运行.我尝试了一些方法,所有这些方法都得到了相同的结果.
选项1:
Start a program"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"google.com选项2:
Start a program"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"google.com"C:\Program Files (x86)\Google\Chrome\Application\"选项3:
Start a programD:\Scripts\openWebSite.bat选项4:
Start a programD:\Scripts\openWebSite.batD:\Scripts\我的问题是一般性的。我何时应该考虑将一条语句拆分为多行?
我自己编写代码,从未在团队中工作过。我总是喜欢使我的代码尽可能紧凑。
例如,代替编写:
depth = depth - randomNumbers.nextInt(depth) -1;
Expression expA = createRandomExp(depth);
Expression expB = createRandomExp(depth);
SubtractionExpression subExp = new SubtractionExpression(expA,expB);
return subExp;
Run Code Online (Sandbox Code Playgroud)
我会写:
return new SubtractionExpression(createRandomExp(depth - randomNumbers.nextInt(depth) - 1), createRandomExp(depth - randomNumbers.nextInt(depth) - 1));
Run Code Online (Sandbox Code Playgroud)
我认为的优点是:
缺点:
randomNumbers.nextInt(depth) -1行业标准是什么?在编写语句时应该考虑什么?一些准则可能会有所帮助。
我遇到了这个问题,但并不能真正回答我的问题。
如果我们的文本文件中有一个 unicode 字符,它不是必须是 2 个字节的数据吗?但是该read()方法一次读取一个字节作为int. 所以如果我们有一个FileInputStream对象fin并且我们调用了int x = fin.read()一次,System.out.println(x)如果只读取了一个字节,我们如何获得完整的字符?(fin.read()不在while循环或任何东西中,它只被调用一次)
我有一个ArrayList的integers,我想删除所有的前导零,代码看起来没事,但ü我得到不同寻常的输出.
输入:
0 0 0 1 9 9
输出:
0 1 9 9
预期产量:
1 9 9
public class Solution {
public ArrayList<Integer> plusOne(ArrayList<Integer> a) {
int flag=0;
//System.out.println(a.size()+" "+a.get(2));
for(int i=0;i<a.size();i++)
{
if(flag==0)
{
//System.out.println("val of i="+i+" "+a.get(i));
if(a.get(i)==0){
a.remove(i);
//System.out.println(flag);
}
else
{
//System.out.println("flag="+flag+" i="+i+" value"+a.get(i));
flag=1;
//System.out.println("flag="+flag+" i="+i+" value"+a.get(i));
}
}
if(flag==1)
break;
}
System.out.println();
return a;
}
}
Run Code Online (Sandbox Code Playgroud) java ×6
arrays ×1
batch-file ×1
cmd ×1
concurrency ×1
email ×1
formatting ×1
graphics2d ×1
io ×1
notify ×1
path ×1
postgresql ×1
psycopg2 ×1
python ×1
python-3.x ×1
ruby ×1
wait ×1