Sunday, August 27, 2017

Can't open Apps from the SearchBar in windows 10


Setting the option "Language for non-Unicode programs" to Chinese(or other languages) or making other language settings in windows 10 may result in the problem of "can't open Apps from SearchBar (click with no response)". Even if you change it back when it happens, the problem won't disappear.

Solution:
1. first change the settings back to the original language
2. set the windows display language to Chinese(or other languages)
3. change the system display language back to English

Some similar problems:
@reference_1_answers.microsoft.com
Q: Windows 10 - Can't Open Apps From Search Bar
@reference_2_superuser.com
Windows 10 - Can't open apps I search for in the start menu
@reference_3_tomshardware.com
can't open apps founded through search
@reference_4_superuser.com
Win 10 - Can't open Desktop Apps from SearchBar

Wednesday, August 23, 2017

T470p: Dual-boot Ubuntu 16.04 and Windows 10 on a PC with UEFI firmware

The key point (red note):
From the Device for boot loader installation, select the efi partition. On the system used for this article, that partition corresponds to /dev/sda2 ( NOTE: select the Windows Boot Manager ), that is, the second partition on the hard drive. Then click on the Install Now button to continue with the rest of the installation.


Wireshark & NPF

Wireshark not working in Win10, for example, you find no network interface showing up to select in Wireshark, it may prompt that "The NPF isn't running" or NOT, anyhow try this: run cmd as administrator, input command: net start npf , then restart wireshark to see if the problem has been solved. If you want to shut down npf service, just run the net stop npf command. 

@reference_1_blog.csdn.net 
关于Wireshark "The NPF driver isn’t running……"解决办法


The npf driver is not visible in your regular "Computer Management" WMI-interface. The npf status is best checked with the command line.
Run a cmd.exe as administrator and run the command sc qc npf.
You should get some output like this:
C:\Windows\system32>sc qc npf
[SC] QueryServiceConfig SUCCESS

SERVICE_NAME: npf
        TYPE               : 1  KERNEL_DRIVER
        START_TYPE         : 2   AUTO_START
        ERROR_CONTROL      : 1   NORMAL
        BINARY_PATH_NAME   : system32\drivers\npf.sys
        LOAD_ORDER_GROUP   :
        TAG                : 0
        DISPLAY_NAME       : NetGroup Packet Filter Driver
        DEPENDENCIES       :
        SERVICE_START_NAME :
If your driver is not properly started, activate it with the command sc start npf
Finally, to start the service automatically, use the command sc config npf start=auto
Remember to run your cmd.exe as administrator when issuing these command.







@reference_2_ask.wireshark.org
NPF driver Problem in Windows 7

Tuesday, August 15, 2017

How to get Thread Name in Runnable's run() method

Thread Names

When you create a Java thread you can give it a name. The name can help you distinguish different threads from each other. For instance, if multiple threads write to System.out it can be handy to see which thread wrote the text. Here is an example:
   Thread thread = new Thread("New Thread") {
      public void run(){
        System.out.println("run by: " + getName());
      }
   };
   thread.start();
   System.out.println(thread.getName());
Notice the string "New Thread" passed as parameter to the Thread constructor. This string is the name of the thread. The name can be obtained via the Thread's getName() method. You can also pass a name to a Thread when using a Runnable implementation. Here is how that looks:
   MyRunnable runnable = new MyRunnable();
   Thread thread = new Thread(runnable, "New Thread");
   thread.start();
   System.out.println(thread.getName());
Notice however, that since the MyRunnable class is not a subclass of Thread, it does not have access to the getName() method of the thread executing it. 

For example, you can't do it like this:
Runnable r = new Runnable(){
   public void run(){
      System.out.println( getName() + " running");  
      // you can't call getName() method here
   }; 
};

Thread.currentThread()

The Thread.currentThread() method returns a reference to the Thread instance executing currentThread() . This way you can get access to the Java Thread object representing the thread executing a given block of code. Here is an example of how to use Thread.currentThread() :
Thread thread = Thread.currentThread();
Once you have a reference to the Thread object, you can call methods on it. For instance, you can get the name of the thread currently executing the code like this:
   String threadName = Thread.currentThread().getName(); 

but you can get thread name like this:
Runnable r = new Runnable(){
   public void run(){
      System.out.println(Thread.currentThread().getName() + " running"); 
      // but you can get thread name like this      
   }; 
};

@reference_1_tutorials.jenkov.com
Creating and Starting Java Threads

Thursday, August 10, 2017

Java Runtime class

Java Runtime class is used to interact with java runtime environment. Java Runtime class provides methods to execute a process, invoke GC, get total and free memory etc. There is only one instance of java.lang.Runtime class is available for one java application.
The Runtime.getRuntime() method returns the singleton instance of Runtime class.



How to shutdown system in Java

You can use shutdown -s command to shutdown system. For windows OS, you need to provide full path of shutdown command e.g. c:\\Windows\\System32\\shutdown.
Here you can use -s switch to shutdown system, -r switch to restart system and -t switch to specify time delay.

public class Runtime2{
public static void main(String args[])throws Exception{
Runtime.getRuntime().exec("shutdown -s -t 0");
}
}

How to shutdown windows system in Java


public class Runtime2{
public static void main(String args[])throws Exception{
Runtime.getRuntime().exec("c:\\Windows\\System32\\shutdown -s -t 0");
}
}

How to restart system in Java


public class Runtime3{
public static void main(String args[])throws Exception{
Runtime.getRuntime().exec("shutdown -r -t 0");
}
}


@reference_1_javatpoint.com
Java Runtime class

Wednesday, August 9, 2017

preemptive scheduling 剥夺式调度

In computing, preemption is the act of temporarily interrupting a task being carried out by a computer system, without requiring its cooperation, and with the intention of resuming the task at a later time. Such changes of the executed task are known as context switches. It is normally carried out by a privileged task or part of the system known as a preemptive scheduler, which has the power to preempt, or interrupt, and later resume, other tasks in the system.

@reference_1_wikipedia
Preemption (computing)

剥夺式(preemptive)调度,又称抢先式调度。当进程/线程正在处理器上运行时,系统可根据所规定的原则剥夺分配给此进程/线程的处理器,并将其移入就绪列队,选择其他进程/线程运行。
 有两种常用的处理器剥夺原则,一是高优先级进程/线程可剥夺低进程/线程;二是当运行进程/线程的时间片用完后被剥夺,在动态改变进程/线程优先级的系统中,经常会出现这样的情况。
剥夺式调度

@reference_3_differencebetween.net
Difference between Preemptive and Non-Preemptive Scheduling in Operating Systems

implements Runnable or extends Thread


两种实现方式的区别和联系:
在程序开发中只要是多线程肯定永远以实现Runnable接口为主,因为实现Runnable接口相比继承Thread类有如下好处:
  • 避免点继承的局限,一个类可以继承多个接口。
  • 适合于资源的共享
以卖票程序为例,通过Thread类完成:

package org.demo.dff;   
class MyThread extends Thread{   
private int ticket=10;   
public void run(){   
for(int i=0;i<20;i++){   
if(this.ticket>0){   
System.out.println("卖票:ticket"+this.ticket--);   
}   
}   
}   
}; 

下面通过三个线程对象,同时卖票:
package org.demo.dff;   
public class ThreadTicket {   
public static void main(String[] args) {   
MyThread mt1=new MyThread();   
MyThread mt2=new MyThread();   
MyThread mt3=new MyThread();   
mt1.start();//每个线程都各卖了10张,共卖了30张票   
mt2.start();//但实际只有10张票,每个线程都卖自己的票   
mt3.start();//没有达到资源共享   
}   
} 
如果用Runnable就可以实现资源共享,下面看例子:
package org.demo.runnable;   
class MyThread implements Runnable{   
private int ticket=10;   
public void run(){   
for(int i=0;i<20;i++){   
if(this.ticket>0){   
System.out.println("卖票:ticket"+this.ticket--);   
}   
}   
}   
}   
package org.demo.runnable;   
public class RunnableTicket {   
public static void main(String[] args) {   
MyThread mt=new MyThread();   
new Thread(mt).start();//同一个mt,但是在Thread中就不可以,如果用同一   
new Thread(mt).start();//个实例化对象mt,就会出现异常   
new Thread(mt).start();   
}   
};
虽然现在程序中有三个线程,但是一共卖了10张票,也就是说使用Runnable实现多线程可以达到资源共享目的。 Runnable接口和Thread之间的联系:
public class Thread extends Object implements Runnable
发现Thread类也是Runnable接口的子类。

@reference_1_developer.51cto.com
Java中Runnable和Thread的区别