stage 89.3 failed 4 times, most recent failure: Lost task 38.4 in stage 89.3 (TID 30100, rhel4.cisco.com): java.io.IOException: No space left on device at java.io.FileOutputStream.writeBytes(Native Method) at java.io.FileOutputStream.write(FileOutputStream.java:326) at org.apache.spark.storage.TimeTrackingOutputStream.write(TimeTrackingOutputStream.java:58) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
这个错误是由于,Spark "scratch" space 不足,具体路径通过
spark.local.dir 参数设置,默认是/tmp。官方对于 scratch space
的解释是
1 2 3
Directory to use for "scratch" space in Spark, including map output files and RDDs that get stored on disk. This should be on a fast, local disk in your system. It can also be a comma-separated list of multiple directories on different disks.
java.lang.IllegalArgumentException: Size exceeds Integer.MAX_VALUE at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:828) at org.apache.spark.storage.DiskStore.getBytes(DiskStore.scala:123) at org.apache.spark.storage.DiskStore.getBytes(DiskStore.scala:132) at org.apache.spark.storage.BlockManager.doGetLocal(BlockManager.scala:51 7) at org.apache.spark.storage.BlockManager.getLocal(BlockManager.scala:432) at org.apache.spark.storage.BlockManager.get(BlockManager.scala:618) at org.apache.spark.CacheManager.putInBlockManager(CacheManager.scala:146 ) at org.apache.spark.CacheManager.getOrCompute(CacheManager.scala:70)
java.nio.ByteBuffer#put() (also
on CharBuffer, ShortBuffer, IntBuffer, LongBuffer, FloatBuffer and DoubleBuffer)
javax.swing.GroupLayout.Group#addComponent()
原型模式(Prototype Pattern)
java.lang.Object#clone()
结构型模式
这些设计模式关注类和对象的组合。继承的概念被用来组合接口和定义组合对象获得新功能的方式
适配器模式(Adapter Pattern)
java.util.Arrays#asList()
java.util.Collections#list()
java.util.Collections#enumeration()
java.io.InputStreamReader(InputStream) (returns a Reader)
java.io.OutputStreamWriter(OutputStream) (returns a Writer)
javax.xml.bind.annotation.adapters.XmlAdapter#marshal() and
桥接模式(Bridge Pattern)
TODO
过滤器模式(Filter、Criteria
Pattern)
组合模式(Composite Pattern)
java.awt.Container#add(Component)
javax.faces.component.UIComponent#getChildren()
装饰器模式(Decorator
Pattern)
All subclasses
of java.io.InputStream, OutputStream, Reader and Writer have a
constructor taking an instance of same type.
java.util.Collections,
the checkedXXX(), synchronizedXXX() and unmodifiableXXX() methods.
javax.servlet.http.HttpServletRequestWrapper and HttpServletResponseWrapper
外观模式(Facade Pattern)
javax.faces.context.FacesContext, it internally uses among others
the abstract/interface
types LifeCycle, ViewHandler, NavigationHandler and many more without
that the enduser has to worry about it (which are however overrideable
by injection).
javax.faces.context.ExternalContext, which internally
uses ServletContext, HttpSession, HttpServletRequest, HttpServletResponse,
etc.
享元模式(Flyweight Pattern)
java.lang.Integer#valueOf(int) (also
on Boolean, Byte, Character, Short, Longand BigDecimal)
代理模式(Proxy Pattern)
java.lang.reflect.Proxy
java.rmi.*
javax.ejb.EJB (explanation here)
javax.inject.Inject (explanation here)
javax.persistence.PersistenceContext
行为型模式
责任链模式(Chain of
Responsibility Pattern)
java.util.logging.Logger#log()
javax.servlet.Filter#doFilter()
命令模式(Command Pattern)
All implementations of java.lang.Runnable
All implementations of javax.swing.Action
解释器模式(Interpreter
Pattern)
java.util.Pattern
java.text.Normalizer
All subclasses of java.text.Format
All subclasses of javax.el.ELResolver
迭代器模式(Iterator Pattern)
All implementations of java.util.Iterator (thus among others
also java.util.Scanner!).
All implementations of java.util.Enumeration
中介者模式(Mediator Pattern)
java.util.Timer (all scheduleXXX() methods)
java.util.concurrent.Executor#execute()
java.util.concurrent.ExecutorService (the invokeXXX() and submit() methods)
java.util.Date (the setter methods do that, Date is internally
represented by a longvalue)
All implementations of java.io.Serializable
All implementations of javax.faces.component.StateHolder
观察者模式(Observer Pattern)
java.util.Observer/java.util.Observable (rarely used in real world
though)*
All implementations of java.util.EventListener (practically all over
Swing thus)
javax.servlet.http.HttpSessionBindingListener
javax.servlet.http.HttpSessionAttributeListener
javax.faces.event.PhaseListener
状态模式(State Pattern)
javax.faces.lifecycle.LifeCycle#execute() (controlled
by FacesServlet, the behaviour is dependent on current phase (state) of
JSF lifecycle)
空对象模式(Null Object
Pattern)
TODO
策略模式(Strategy Pattern)
java.util.Comparator#compare(), executed by among
others Collections#sort().
javax.servlet.http.HttpServlet, the service() and
all doXXX() methods take HttpServletRequest and HttpServletResponse and
the implementor has to process them (and not to get hold of them as
instance variables!).
javax.servlet.Filter#doFilter()
模板模式(Template Pattern)
All non-abstract methods
of java.io.InputStream, java.io.OutputStream, java.io.Reader and java.io.Writer.
All non-abstract methods
of java.util.AbstractList, java.util.AbstractSet and java.util.AbstractMap.
javax.servlet.http.HttpServlet, all the doXXX() methods by default sends
a HTTP 405 "Method Not Allowed" error to the response. You're free to
implement none or any of them.
访问者模式(Visitor Pattern)
javax.lang.model.element.AnnotationValue and AnnotationValueVisitor
javax.lang.model.element.Element and ElementVisitor
javax.lang.model.type.TypeMirror and TypeVisitor
java.nio.file.FileVisitor and SimpleFileVisitor
javax.faces.component.visit.VisitContext and VisitCallback
一个 Java 程序是由若干个 class
文件组成。当程序在运行时,即会调用该程序的一个入口函数来调用系统的相关功能,而这些功能都被封装在不同的
class 文件当中,所以经常要从这个 class 文件中要调用另外一个 class
文件中的方法,如果另外一个 class 文件不存在的,则会引发
ClassNotFoundException。
程序在启动的时候,并不会一次性加载程序所要用的所有 class
文件,而是根据程序的需要,通过 Java
的类加载机制(ClassLoader)来动态加载某个 class
文件到内存当中的,从而只有 class 文件被载入到了内存之后,才能被其它
class 所引用。所以 ClassLoader 就是用来动态加载 class
文件到内存当中用的。
在 JVM 在搜索类的时候,又是如何判定两个 class 是相同的呢?JVM
在判定两个 class
是否相同时,不仅要判断两个类名是否相同,而且要判断是否由同一个类加载器实例加载的。只有两者同时满足的情况下,JVM
才认为这两个 class 是相同的。就算两个 class 是同一份 class
字节码,如果被两个不同的 ClassLoader 实例所加载,JVM
也会认为它们是两个不同 class。比如有一个 Java 类 SimpleClass.java,javac
编译之后生成字节码文件 SimpleClass.class,ClassLoaderA 和 ClassLoaderB
这两个类加载器并读取了 SimpleClass.class 文件,并分别定义出了
java.lang.Class 实例来表示这个类,对于 JVM
来说,它们是两个不同的实例对象,但它们确实是同一份字节码文件,如果试图将这个
Class 实例生成具体的对象进行转换时,就会抛运行时异常
java.lang.ClassCaseException,提示这是两个不同的类型。
如何自定义 ClassLoader
何时需要自己定制
ClassLoader?
需要加载外部的 class 而这些
class,默认的类加载器是加载不到的。例如,文件系统比较特殊或者需要从网络中加载一个
class 字节流等。
需要实现 class 的隔离性。常用的 web 服务器,如
weblogic、tomcat、jetty 等都实现这样的类加载器。这些类加载器主要做到:
1)实现加载 Web 应用指定目录下的 jar 和 class。 2)实现部署在容器中的
Web 应用程共同使用的类库的共享。 3)实现部署在容器中各个 Web
应用程序自己私有类库的相互隔离。