Skip to content

Instantly share code, notes, and snippets.

View jackblack369's full-sized avatar
🚀
get started

Dongwei jackblack369

🚀
get started
View GitHub Profile
@jackblack369
jackblack369 / build-design-patter.md
Created February 26, 2019 07:20
[code-build-design-pattern] #java #design pattern
  • Computer

package com.journaldev.design.builder;

public class Computer {
	
	//required parameters
	private String HDD;
	private String RAM;
@jackblack369
jackblack369 / Java Design Patterns.md
Last active February 27, 2019 01:49
[learn-Java Design Patterns] #java #website

Creational Design Patterns

Singleton

  • different approaches to implement:
    • Private constructor to restrict instantiation of the class from other classes.
    • Private static variable of the same class that is the only instance of the class.
    • Public static method that returns the instance of the class, this is the global access point for outer world to get the instance of the singleton class.
  • design concerns with the implementation
    • Eager initialization
@jackblack369
jackblack369 / grpc.md
Created February 19, 2019 06:57
[code-grpc] #java #grpc
  • generate code based proto

protoc --proto_path=扫描目录 --java_out=代码生成目录 proto文件目录,.ie protoc --proto_path=src --java_out=build/gen src/foo.proto

@jackblack369
jackblack369 / notify thread.java
Created February 16, 2019 10:06
[code-thread] #java
class Shared
{
synchronized void waitMethod()
{
Thread t = Thread.currentThread();
System.out.println(t.getName()+" is releasing the lock and going to wait");
try
{
@jackblack369
jackblack369 / stop thread2.java
Created February 16, 2019 09:34
[code-thread] #java
class MyThread extends Thread
{
@Override
public void run()
{
while (!Thread.interrupted())
{
System.out.println("I am running....");
}
@jackblack369
jackblack369 / to stop thread.java
Created February 16, 2019 09:09
[code-thread] #java
class MyThread extends Thread
{
//Initially setting the flag as true
private volatile boolean flag = true;
//This method will set flag as false
public void stopRunning()
{
@jackblack369
jackblack369 / learn-stream.md
Last active February 27, 2019 15:12
[learn-stream] #java

Creating Java Streams

  1. We can use Stream.of() to create a stream from similar type of data. For example, we can create Java Stream of integers from a group of int or Integer objects.
Stream<Integer> stream = Stream.of(1,2,3,4);
  1. We can use Stream.of() with an array of Objects to return the stream. Note that it doesn’t support autoboxing, so we can’t pass primitive type array.
Stream<Integer> stream = Stream.of(new Integer[]{1,2,3,4}); 
//works fine
@jackblack369
jackblack369 / personal word.md
Last active February 15, 2019 08:47
word #word

GUO

  • 谎言不攻不破
  • 没经历过事,成不了大事
  • 母亲给了你生命,也会把生命给你

Real person

  • 极深的暴力当中隐藏着极致的温柔 (北野武)
@jackblack369
jackblack369 / tomcat.md
Created January 18, 2019 10:42
[A&Q] #tomcat
  • 项目部署到linux的tomcat中,验证码在页面中刷新不了,需要修改catalina.sh,添加JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true"配置
@jackblack369
jackblack369 / html.md
Created January 18, 2019 07:35
[html] #html
  • 页面跳转,需要使用 i 标签,不能使用 button 标签,因为在button的点击事件中,window.location.href不起作用