小编use*_*988的帖子

简单线程是串联运行的吗?(第二个线程在第一个线程停止之前不会运行)

我一个接一个地开始两个线程.第一个线程是从输入读取循环,另一个是在循环中检查某些条件以向另一个发送中断.

问题是我先启动的两个线程中的任何线程都不会让另一个线程停止.如果我开始读取从不运行另一个线程,直到它完成,如果我启动另一个线程正在检查循环中的条件,它不会在代码中向前移动,直到条件为真并退出循环.这样做的正确方法是什么?示例代码如下:

线程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)

java multithreading

3
推荐指数
1
解决办法
284
查看次数

阅读IFrame cookie

我创建了一个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吗?

html javascript cookies iframe

3
推荐指数
1
解决办法
9407
查看次数

标签 统计

cookies ×1

html ×1

iframe ×1

java ×1

javascript ×1

multithreading ×1