码迷,mamicode.com
首页 > 编程语言 > 详细

Java Notes-5

时间:2014-12-14 17:15:15      阅读:291      评论:0      收藏:0      [点我收藏+]

标签:java

-Bounds use the  extends keyword

and some new syntax to limit the parameter types that may be applied to a generic type.

class EmployeeList< T extends Employee & Ranked & Printable > { ... }

-As we’ll see in this section, wildcards are Java’s way of introducing polymorphism into
the type parameter portion of the generic equation.

bubuko.com,布布扣

-The unbounded wildcard instantiation is a kind of  supertype of all of these concrete
instantiations. 

bubuko.com,布布扣

-We saw the  extends construct used to specify an upper bound for both type variables
and wildcard instantiations. It implies a type that is “at the top” of the object hierarchy
for the bound. 

bubuko.com,布布扣

-Generic methods can
appear in any class (not just generic classes) and are very useful for a wide variety of
applications.

-Like generic classes, generic methods have a parameter type declaration using the  <>
syntax. This syntax appears before the return type of the method:

bubuko.com,布布扣

-In general, wildcard instantiations of generics can be used as the base type for arrays in
the same way that concrete instantiations can. Let’s look at an example:

bubuko.com,布布扣

bubuko.com,布布扣

-All execution in Java is associated with a  Thread object, beginning with a “main” thread
that is started by the Java VM to launch your application. A new thread is born when
we create an instance of the  java.lang.Thread class

bubuko.com,布布扣

-Any class that contains an appropriate  run() method can declare that it implements the
Runnable interface. An instance of this class is then a runnable object that can serve as
the target of a new thread.

-A newly born thread remains idle until we give it a figurative slap on the bottom by
calling its  start() method. The thread then wakes up and proceeds to execute the  run()
method of its target object.  start() can be called only once in the lifetime of a thread.

bubuko.com,布布扣

bubuko.com,布布扣

bubuko.com,布布扣

bubuko.com,布布扣

-. We could also
start the thread without saving a reference to it if we won’t be using it later:

bubuko.com,布布扣

-The methods  wait() and  join() coordinate the execution of two or more threads.
We’ll discuss them in detail when we talk about thread synchronization later in this
chapter.
? The  interrupt() method wakes up a thread that is sleeping in a  sleep() or  wait()
operation or is otherwise blocked on a long I/O operation. 

-Finally, if you need to coordinate your activities with another thread by waiting for it
to complete its task, you can use the  join() method.

-A thread continues to execute until one of the following happens:
? It explicitly returns from its target  run() method.
? It encounters an uncaught runtime exception.
? The evil and nasty deprecated  stop() method is called.

- thread can live on, even after what is ostensibly the
part of the application that created it has finished. 

-the  Devil thread sets its daemon status when it is created. If any  Devil
threads remain when our application is otherwise complete, the runtime system kills
them for us. 

bubuko.com,布布扣

-The AWT thread is not a daemon thread, so it doesn’t
exit automatically when other application threads have completed, and the developer
must call  System.exit() explicitly. 

-Applets are embeddable Java applications that are expected to start and stop themselves
on command, possibly many times in their lifetime. 

-or example, suppose we implemented a  SpeechSynthesizer class that contains a  say()
method. We don’t want multiple threads calling  say() at the same time because we
wouldn’t be able to understand anything being said. 

bubuko.com,布布扣

-if one thread were changing the values of the variables in
setRow() at the same moment another thread was reading the values in  sumRow() . To
prevent this, we have marked both methods as  synchronized . 


Java Notes-5

标签:java

原文地址:http://blog.csdn.net/yu444/article/details/41706025

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!