分类 Default 下的文章

Remember the day, I borrowed your brand new car and dented it?
I thought you'd kill me
but you didn't.

Remember that day, I said something awful due to my bad temper?
I thought you'd be mad at me
but you didn't.

Remember that day , I vomited strawberry pie all over your new carpet?
I thought you'd hate me
but you didn't.

Remember that day, I dragged you to the beach, and it really was raining as you said it would?
I thought you'd say."I told you so."
but you didn't.

Remember that day, I forgot to tell you that dance was formal wear. and you ended up wearing jeans?
I thought you'd abandon me.
But you didn't.

Yes, there were lots of thing you didn't do,
but you put up with me,
loved me,
protected me.
There were lots and lots of things I wanted to make up to me.
when you returned from Vietnam.
But you didn't.

之前的肉鸡挂了,部署的项目也访问不了。继续v2ray--2018-08-03 14:02更新


博主使用的是Ubuntu系统,其他发行版的设置应该差不多。如需更多ssr客户端使用,可以去我的down盘里找(资源来自网络--我不对它们负责哟)
前提:

1.请自备ssr账号,本文章只是记录在Linux下使用ssr客户端FQ

2.安装好git

安装命令行/图形界面的ssr
3.1.以命令行方式--往下看有图形ssr安装简单教程

wget http://www.djangoz.com/ssr
sudo mv ssr /usr/local/bin
sudo chmod 766 /usr/local/bin/ssr
ssr install
ssr config  #ssr的配置

基本使用
ssr配置

  • ssr config的配置(对应使用的ssr配就好了--就是复制粘贴的事).btw:默认使用vim打开

2.浏览器设置代理

  • 在ssr配置中默认的本机代理为127.0.0.1 端口为1080.当然你可以修改(如果端口被占用的话)
  • 浏览器下载一个插件--对接本机的代理端口(1080/修改后的端口)使用(不同于window下可以直接使用)
    插件SwitchyOmega的github更新地址
  • SwitchyOmega的使用(第一次搞的时候懵了 ╮(╯▽╰)╭)

    代理服务器那里,如图1示,填完点击应用选项就好了

    国内的网站点击系统代理,FQ就点击你设置那个情景模式(proxy)

3.设置代理到系统

前面设置通过浏览器使用本机的代理端口实现FQ,有的时候需要其他软件FQ使用。这时候就要将代理应用到这个系统(其实大部分都是使用浏览器代理)

PS:节点质量不好建议使用完后关闭

  • ssr的使用命令--查看帮助

    ssr help

设置开机启动

sudo vim /etc/rc.local

#在exit 0前添加sudo ssr start

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
sudo ssr start
exit 0

4.以图形界面方式(electron-ssr)

[各版本下载地址](https://github.com/erguotou520/electron-ssr/releases)
我使用的系统支持pacman的Linux所以下载xxx.pacman结尾的文件到本地后再以:
sudo pacman -U xxx.pacman安装

deb结尾的文件可以用:
sudo dpkg -i electron-ssrxxxx.deb
好像还要安装python--可能我之前已经安装好了,第一次安装就成功

基本使用
傻瓜式图形看到界面应该就是用--略

有兴趣可以了解:
V2ray--已经在用了hhhhhhh
https://toutyrater.github.io/
ssr安装:安装


使用bwg的ssr被封了好多次了,还花钱换了一次ip。是时候用v2ray了

  1. v2ray与其他(ss,ssr)的好处,blablabla官方文档

安装

  1. 首先需要一个肉鸡(买了hiformance的,一年才¥64.35),debian9加bbr加速这个神奇的东吸
  2. 服务器端搭好v2ray

    使用一键脚本(珍惜生命啊),作者文章链接
    选择1安装v2ray,之后的都可以回车直接默认(如果还需要ss也可以选,感觉没必要)
bash <(curl -s -L https://233blog.com/v2ray.sh)
  1. 安装完成后输入v2ray link显示客户端的v2ray配置链接,复制链接到浏览器打开下载(xxxxx==_233blog_v2ray结尾的json文件)
  2. 下载v2ray客户端

    选择对应的端下载,(这里我下载v2ray-windows-64.zip),解压
  3. 连接服务器

    将步骤4中下载的json文件内容覆盖到解压目录中的config.json(可以将原来的config.json复制保存一份--习惯)
  4. 理论上执行解压目录中的v2ray(跳出个命令行窗口监听执行)或者wv2ray(后台执行)就可以开启v2ray客户端使用,
    但也可以使用图形软件(功能易上手),这里使用的是v2rayN(需要在同解压的v2ray客户端同一目录才能使用哟)
  5. 使用v2rayN开启v2ray使用

    打开v2rayN后,点击左上角的的服务器,选择下拉列表的--添加[vmess]服务器 (vmess是v2ray使用的一个协议)
    必填:地址,端口,用户id,额外id,加密(根据config.json填好就行了)
  6. 所有东吸都好了,打开浏览器试试??
  7. 安卓V2RayNG。华为的手机商场有个actinium的软件,导入配置文件就可以使用,不到5M,还可以。ios商店搜Kitsunebi及Kitsunebi Lite

转载自: https://www.djangoz.com/2017/08/16/linux_setup_ssr/

ref:
1各种
2百度
3搜索
4结果
5可以参考参考

  1. 回收作用
    垃圾回收可以有效的防止内存泄露,有效的使用空闲的内存
    (内存泄露:指该内存空间使用完毕后未回收,在不涉及复杂数据结构的一般情况下,java的内存泄露表现为一个内存对象的生命周期超出了程序需要它的时间长度)
    如果不进行垃圾回收,内存迟早都会被消耗空
  2. 回收对象
    那些不可能再被任何途径使用的对象
  3. 垃圾回收实现原则
  4. 发现无用的信息对象;
  5. 回收将无用对象占用的内存空间。使该空间可被程序再次使用。
  6. 如何确定一个对象是否可以被回收
  7. 引用计数法--无法处理循环引用的问题
    原理是此对象有一个引用,即增加一个计数,删除一个引用则减少一个计数。
    垃圾回收时,只用收集计数为 0 的对象。
  8. 可达性分析算法:判断对象的引用链是否可达
  9. 垃圾收集算法
  10. 标记清除算法--需要暂停整个应用,同时,会产生内存碎片
    第一阶段从引用根节点开始标记所有被引用的对象
    第二阶段遍历整个堆,把未标记的对象清除
  11. 复制算法--需要两倍内存空间
    此算法把内存空间划为两个相等的区域,每次只使用其中一个区域。
    垃圾回收时,遍历当前使用区域,把正在使用中的对象复制到另外一个区域中;
  12. 标记整理算法
    第一阶段从根节点开始标记所有被引用对象
    第二阶段遍历整个堆,把清除未标记对象并且把存活对象 “压缩” 到堆的其中一块,按顺序排放
  13. 分代收集算法
  14. 回收算法的直接应用--垃圾收集器

ref:
《深入java虚拟机》
图解Java 垃圾回收机制

结构型模式:适配器模式、装饰模式、代理模式、外观模式、桥接模式、组合模式、享元模式

    1. 代理模式(Proxy)
代理模式就是多一个代理类出来,替原对象进行一些操作
为其他对象提供一个代理以控制对某个对象的访问
使用代理模式,可以将功能划分的更加清晰,有助于后期维护
比如我们在租房子的时候回去找中介,为什么呢?因为你对该地区房屋的信息掌握的不够全面
希望找一个更熟悉的人去帮你做,此处的代理就是这个意思
public interface Sourceable {  
    public void method();  
}  
public class Source implements Sourceable {  
  
    @Override  
    public void method() {  
        System.out.println("the original method!");  
    }  
} 
public class Proxy implements Sourceable {  
    private Source source;  
    public Proxy(){  
        super();  
        this.source = new Source();  
    }  
    @Override  
    public void method() {  
        before();  
        source.method();  
        atfer();  
    }  
    private void atfer() {  
        System.out.println("after proxy!");  
    }  
    private void before() {  
        System.out.println("before proxy!");  
    }  
}  
public class ProxyTest {  
    public static void main(String[] args) {  
        Sourceable source = new Proxy();  
        source.method();  
    }  
}
//输出
before proxy!
the original method!
after proxy!
在Proxy类中不仅执行了委托类Source 的method方法还增加了两个功能
  • 静态代理

    上面例子就是静态代理--
1.为了保持行为的一致性,代理类和委托类通常会实现相同的接口
2.代理类和委托类实现了相同的接口,这样就出现了大量的代码重复
3.代理对象只服务于一种类型(如上的Sourceable )的对象,如果要服务多类型的对象 程序开发中必然会产生许多的代理类
  • 动态代理

    动态代理是在运行时,通过反射机制实现动态代理,并且能够代理各种类型的对象
    在Java中要想实现动态代理机制,需要java.lang.reflect.InvocationHandler接口和 java.lang.reflect.Proxy 类的支持
public interface UserManager {
        public void addUser(String userId, String userName);
        public void delUser(String userId);
        public String findUser(String userId);
        public void modifyUser(String userId, String userName);
}
public class UserManagerImpl implements UserManager {
    @Override
    public void addUser(String userId, String userName) {
        System.out.println("UserManagerImpl.addUser");
    }
    @Override
    public void delUser(String userId) {
        System.out.println("UserManagerImpl.delUser");
    }
    @Override
    public String findUser(String userId) {
        System.out.println("UserManagerImpl.findUser");
        return "张三";
    }
    @Override
    public void modifyUser(String userId, String userName) {
        System.out.println("UserManagerImpl.modifyUser");
    }
}
//动态代理类只能代理接口(不支持抽象类),代理类都需要实现InvocationHandler类,实现invoke方法。
//该invoke方法就是调用被代理接口的所有方法时需要调用的,该invoke方法返回的值是被代理接口的一个实现类
public class LogHandler implements InvocationHandler {
    // 目标对象
    private Object targetObject;
    //绑定关系,也就是关联到哪个接口(与具体的实现类绑定)的哪些方法将被调用时,执行invoke方法。            
    public Object newProxyInstance(Object targetObject){
        this.targetObject=targetObject;
        //该方法用于为指定类装载器、一组接口及调用处理器生成动态代理类实例  
        //第一个参数指定产生代理对象的类加载器,需要将其指定为和目标对象同一个类加载器
        //第二个参数要实现和目标对象一样的接口,所以只需要拿到目标对象的实现接口
        //第三个参数表明这些被拦截的方法在被拦截时需要执行哪个InvocationHandler的invoke方法
        //根据传入的目标返回一个代理对象
        return Proxy.newProxyInstance(targetObject.getClass().getClassLoader(),
                targetObject.getClass().getInterfaces(),this);
    }
    @Override
    //关联的这个实现类的方法被调用时将被执行
    /*InvocationHandler接口的方法,proxy表示代理,method表示原对象被调用的方法,args表示方法的参数*/
    public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable {
        System.out.println("start-->>");
        for(int i=0;i<args.length;i++){
            System.out.println(args[i]);
        }
        Object ret=null;
        try{
            /*原对象方法调用前处理日志信息*/
            System.out.println("satrt-->>");
            //-----------调用目标方法-------------
            ret=method.invoke(targetObject, args);
            /*原对象方法调用后处理日志信息*/
            System.out.println("success-->>");
        }catch(Exception e){
            e.printStackTrace();
            System.out.println("error-->>");
            throw e;
        }
        return ret;
    }
}
public class Client {
    public static void main(String[] args){
        LogHandler logHandler=new LogHandler();
        UserManager userManager=(UserManager)logHandler.newProxyInstance(new UserManagerImpl());
        //UserManager userManager=new UserManagerImpl();
        userManager.addUser("1111", "张三");
    }
}
//结果
start-->>
1111
张三
satrt-->>
UserManagerImpl.addUser
success-->>

ref:
23种设计模式全解析
JAVA学习篇--静态代理VS动态代理

问题解决+经验复用
设计模式原则:对扩展开放,对修改关闭,使用继承、抽象类、接口、低耦合

创建型模式:单例模式、抽象工厂模式、建造者模式、工厂模式、原型模式。

  • 1.单例

    确保一个类只有一个实例,并提供该实例的全局访问。
public class Singleton {
    private volatile static Singleton uniqueInstance;
    private Singleton() {
    }
    public static Singleton getUniqueInstance() {
        if (uniqueInstance == null) {
            synchronized (Singleton.class) {
                if (uniqueInstance == null) {
                    uniqueInstance = new Singleton();
                }
            }
        }
        return uniqueInstance;
    }
}
//双重校验锁先判断 uniqueInstance 是否已经被实例化,如果没有被实例化,那么才对实例化语句进行加锁。
uniqueInstance = new Singleton(); 
1,分配内存空间
2,初始化对象
3,将 uniqueInstance 指向分配的内存地址
//由于 JVM 具有指令重排的特性,有可能执行顺序变为了 1>3>2.使用 volatile 可以禁止 JVM 的指令重排,保证在多线程环境下也能正常运行。
  • 2.工厂模式--类的创建依赖工厂类
  • 2.1简单工厂方法

    在创建一个对象时不向客户暴露内部细节,并提供一个实现的通用接口。
public interface Sender {
    public void Send();
}
public class MailSender implements Sender {
    @Override
    public void Send() {
        System.out.println("this is mailsender!");
    }
}
public class SmsSender implements Sender {
    @Override
    public void Send() {
        System.out.println("this is sms sender!");
    }
}
public class SendFactory {
    public Sender produce(String type) {
        if ("mail".equals(type)) {
            return new MailSender();
        } else if ("sms".equals(type)) {
            return new SmSender();
        } else {
            System.out.println("请输入正确的类型!");
            return null;
        }
    }
}
public class FactoryTest {
    public static void main(String[] args) {
        SendFactory sendFactory = new SendFactory();
        Sender sender = sendFactory.produce("mail");
        sender.send();
    }
}
在main方法中通过指定参数调用工厂方法生成与参数对应的对象
  • 2.2多个工厂方法

    在普通工厂方法模式中,如果传递的字符串出错,则不能正确创建对象,而多个工厂方法模式是提供多个工厂方法,分别创建对象
public class SendFactory {
    public Sender produceMail(){
        return new MailSender();
    }
    public Sender produceSms(){
        return new SmsSender();
    }
}    
public class FactoryTest {
    public static void main(String[] args) {
        SendFactory factory = new SendFactory();
        Sender sender = factory.produceMail();
        sender.Send();
    }
}
  • 2.3静态工厂方法--方便

    不需要创建实例,直接调用即可
public class SendFactory {
    
    public static Sender produceMail(){
        return new MailSender();
    }
    
    public static Sender produceSms(){
        return new SmsSender();
    }
}
public class FactoryTest {
    public static void main(String[] args) {    
        Sender sender = SendFactory.produceMail();
        sender.Send();
    }
}
  • 2.4抽象工厂

    避免对工厂类的直接修改,抽象工厂增加新的功能只需增加一个新的工厂类,而不需要修改原来的代码
public interface Sender {
    public void Send();
}
public class MailSender implements Sender {
    @Override
    public void Send() {
        System.out.println("this is mailsender!");
    }
}
public class SmsSender implements Sender {
    @Override
    public void Send() {
        System.out.println("this is sms sender!");
    }
}

程序只有一个发送的功能,SmsSender、MailSender两个端为功能的实现;现在需要再加一个新建对象的功能

public interface Provider {
    public Sender produce();
}
public class SendMailFactory implements Provider  implements Sender {
    @Override
    public void Send() {
        System.out.println("this is mailsender!");
    }
    @Override
    public Sender produce(){
        return new MailSender();
    }
}
public class SendSmsFactory implements Provider  implements Sender{
 
    @Override
    public Sender produce() {
        return new SmsSender();
    }
        @Override
    public void Send() {
        System.out.println("this is sms sender!");
    }
}
  • 3.建造者模式

    建造者模式就是前面抽象工厂模式和最后的Test结合起来,将很多功能集成到一个类里,这个类可以创造出比较复杂的东西
public interface Sender {
    public void Send();
}
public class MailSender implements Sender {
    @Override
    public void Send() {
        System.out.println("this is mailsender!");
    }
}
public class SmsSender implements Sender {
    @Override
    public void Send() {
        System.out.println("this is sms sender!");
    }
}
public class Builder {
    private List<Sender> list = new ArrayList<Sender>();
    public void produceMailSender(int count){
        for(int i=0; i<count; i++){
            list.add(new MailSender());
        }
    }
    public void produceSmsSender(int count){
        for(int i=0; i<count; i++){
            list.add(new SmsSender());
        }
    }
}
public class Test {
    public static void main(String[] args) {
        Builder builder = new Builder();
        builder.produceMailSender(10);
    }
}
  • 4.原型模式

    将一个对象作为原型,对其进行复制、克隆,产生一个和原对象类似的新对象
public class Prototype implements Cloneable {
    public Object clone() throws CloneNotSupportedException {
        Prototype proto = (Prototype) super.clone();
        return proto;
    }
}

浅复制:将一个对象复制后,基本数据类型的变量都会重新创建,而引用类型,指向的还是原对象所指向的。
深复制:将一个对象复制后,不论是基本数据类型还有引用类型,都是重新创建的。简单来说,就是深复制进行了完全彻底的复制,而浅复制不彻底。

public class Prototype implements Cloneable, Serializable {
    private static final long serialVersionUID = 1L;
    private String string;
    private SerializableObject obj;
    /* 浅复制 */
    public Object clone() throws CloneNotSupportedException {
        Prototype proto = (Prototype) super.clone();
        return proto;
    }
    /* 深复制 */
    public Object deepClone() throws IOException, ClassNotFoundException {
        /* 写入当前对象的二进制流 */
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(this);
        /* 读出二进制流产生的新对象 */
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bis);
        return ois.readObject();
    }
    public String getString() {
        return string;
    }
    public void setString(String string) {
        this.string = string;
    }
    public SerializableObject getObj() {
        return obj;
    }
    public void setObj(SerializableObject obj) {
        this.obj = obj;
    }
}
class SerializableObject implements Serializable {
    private static final long serialVersionUID = 1L;
}