我一个接一个地开始两个线程.第一个线程是从输入读取循环,另一个是在循环中检查某些条件以向另一个发送中断.
问题是我先启动的两个线程中的任何线程都不会让另一个线程停止.如果我开始读取从不运行另一个线程,直到它完成,如果我启动另一个线程正在检查循环中的条件,它不会在代码中向前移动,直到条件为真并退出循环.这样做的正确方法是什么?示例代码如下:
线程1)
public class InterruptionThread extends Thread {
public void run() {
while (condition not true) {
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (condition true) {
do some work
return;
}
}
}
Run Code Online (Sandbox Code Playgroud)
线程2)
public class ReadingThread extends Thread{
public void run() {
int input;
while (true) {
try {
input = stdInput.read();
} catch (IOException e) {
e.printStackTrace();
return;
}
System.out.print((char) input);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我创建了一个iframe,我在其中加载了一个网站(我没有访问这个网站 - 它不是由我写的)
<script type="text/javascript">
var el = document.createElement("iframe");
el.setAttribute('id', 'ifrm');
document.body.appendChild(el);
el.setAttribute('src', 'http://AWEBSITE.com/');
alert(document.getElement("iframe").cookie); //This doesnt work.....
</script>
Run Code Online (Sandbox Code Playgroud)
我可以用某种方式使用javascript来读取iframe的cookie吗?