当前位置: 首页 > news >正文

网站开发及后期维护wordpress如何添加导航

网站开发及后期维护,wordpress如何添加导航,无法进入wordpress,搭建电商网站通常我们会有这样的需求#xff0c;即停止一个线程。在java的api中有stop、suspend等方法可以达到目的#xff0c;但由于这些方法在使用上存在不安全性#xff0c;会带来不好的副作用#xff0c;不建议被使用。具体原因可以参考Why is Thread.stop deprecated。在本文中即停止一个线程。在java的api中有stop、suspend等方法可以达到目的但由于这些方法在使用上存在不安全性会带来不好的副作用不建议被使用。具体原因可以参考Why is Thread.stop deprecated。在本文中将讨论中断在java中的使用。中断在java中主要有3个方法interrupt(),isInterrupted()和interrupted()。interrupt()在一个线程中调用另一个线程的interrupt()方法即会向那个线程发出信号——线程中断状态已被设置。至于那个线程何去何从由具体的代码实现决定。isInterrupted()用来判断当前线程的中断状态(true or false)。interrupted()是个Thread的static方法用来恢复中断状态名字起得额。接下来看看具体在代码中如何使用。interrupt()不能中断在运行中的线程它只能改变中断状态而已。public class InterruptionInJava implementsRunnable{public static void main(String[] args) throwsInterruptedException {Thread testThread new Thread(new InterruptionInJava(),InterruptionInJava);//start threadtestThread.start();Thread.sleep(1000);//interrupt threadtestThread.interrupt();System.out.println(main end);}Overridepublic voidrun() {while(true){if(Thread.currentThread().isInterrupted()){System.out.println(Yes,I am interruted,but I am still running);}else{System.out.println(not yet interrupted);}}}}结果显示被中断后仍旧运行不停打印Yes,I am interruted,but I am still running那么如何正确中断既然是只能修改中断状态那么我们应该针对中断状态做些什么。public class InterruptionInJava implementsRunnable{public static void main(String[] args) throwsInterruptedException {Thread testThread new Thread(new InterruptionInJava(),InterruptionInJava);//start threadtestThread.start();//Thread.sleep(1000);//interrupt threadtestThread.interrupt();System.out.println(main end);}Overridepublic voidrun() {while(true){if(Thread.currentThread().isInterrupted()){System.out.println(Yes,I am interruted,but I am still running);return;}else{System.out.println(not yet interrupted);}}}}修改代码在状态判断中如上添加一个return就okay了。但现实中我们可能需要做的更通用不禁又要发出天问如何中断线程答案是添加一个开关。public class InterruptionInJava implementsRunnable{private volatile static boolean on false;public static void main(String[] args) throwsInterruptedException {Thread testThread new Thread(new InterruptionInJava(),InterruptionInJava);//start threadtestThread.start();Thread.sleep(1000);InterruptionInJava.on true;System.out.println(main end);}Overridepublic voidrun() {while(!on){if(Thread.currentThread().isInterrupted()){System.out.println(Yes,I am interruted,but I am still running);}else{System.out.println(not yet interrupted);}}}}这表明是成功中断了的这种开关的方式看起来包治百病但是当遇到线程阻塞时就会很无奈了正如下面代码所示public class InterruptionInJava implementsRunnable{private volatile static boolean on false;public static void main(String[] args) throwsInterruptedException {Thread testThread new Thread(new InterruptionInJava(),InterruptionInJava);//start threadtestThread.start();Thread.sleep(1000);InterruptionInJava.on true;System.out.println(main end);}Overridepublic voidrun() {while(!on){try{Thread.sleep(10000000);}catch(InterruptedException e) {System.out.println(caught exception: e);}}}}线程被阻塞无法被中断。这时候救世主interrupt函数又回来了它可以迅速中断被阻塞的线程抛出一个InterruptedException把线程从阻塞状态中解救出来,show the code。public class InterruptionInJava implementsRunnable{private volatile static boolean on false;public static void main(String[] args) throwsInterruptedException {Thread testThread new Thread(new InterruptionInJava(),InterruptionInJava);//start threadtestThread.start();Thread.sleep(1000);InterruptionInJava.on true;testThread.interrupt();System.out.println(main end);}Overridepublic voidrun() {while(!on){try{Thread.sleep(10000000);}catch(InterruptedException e) {System.out.println(caught exception right now: e);}}}这种情形同样适用io阻塞通常io阻塞会立即抛出一个SocketException类似于上面说的InterruptedException。
http://www.huolong8.cn/news/137165/

相关文章:

  • 建设部网标准下载网站asp企业网站模板
  • 建设银行网站可以打印流水吗手机网游
  • 旅游网站建设流程步骤网站建设和管理存在的问题
  • 上海网站建设明细报价表如何建外贸网站
  • 做商城网站需要什么条件湖南做网站 地址磐石网络
  • seo站长工具腾讯云wordpress镜像
  • 做网站的成功案例深入解析 wordpress
  • 企业网站模板下载psd格式电商法规定企业网站必须做3年
  • 企业免费建站网站仿中国化妆品网站模板
  • 网站伪静态有什么用有什么好的设计网站
  • 网站设计制作的连接方式企业网站改版seo
  • 手机网站你了解的高端网站制作 专业制作平台
  • 南宁企业网站设计中国建设银行预约网站
  • 一个网站 两个数据库gif8.net基于wordpress
  • 丰都网站建设联系电话网站开发的服务器是什么
  • 做网站的网站wordpress中文编辑器插件
  • 网站程序开发的基本步骤优化网站内链
  • 网站设计一般多少钱一个页面wordpress本地化图片
  • 资阳住房和城乡建设厅网站网页设计总结论文
  • 沧州国外网站建设如何写网站文案
  • 情人做网站学网站开发需要学那些
  • 企业免费建站网站wordpress好用的文件管理
  • 网站系统运行环境文化建设的名言警句
  • 如何找回网站后台密码网页设计作品模板
  • 做哪些网站不受法律保护淮南北京网站建设
  • 企业网站开发价格网络营销外包专家
  • vue框架做的网站吴正斌建盏简介
  • 网站开发费 会计科目网站开发设计书籍
  • 网站与备案信息不符制作小程序官网
  • 两个wordpress数据同步巩义网站建设优化公司