2020-6-5 --记一次杭州面试经历(惨)

149 阅读4分钟
  1. DUBBO的注册方式
       答:共有三种注册方式

              (1): main 方法

              这种方式需要在项目中新建一个类来专门执行main方法,去加载配置文件。所以这种方式更加适合开发阶段的使用,方便开发人员进行单元测试。  

   public class provider { 
        public static void main(String[] args) throws Exception { 
            ClassPathXmlApplicationContext context = 
                        new ClassPathXmlApplicationContext( 
                        new String[] { "applicationContext-service.xml" }); 
            context.start(); 
            System.out.println("成功"); 
            System.in.read(); // 为保证服务一直开着,利用输入流的阻塞来模拟 
    } 
} 
            (2):web容器(我就用过这一种)

            这种方式不需要添加任何多余的类或方法,只需要将provider注册服务的配置文件放在web.xml中加载到web容器中即可。 这种方式服务注册的配置文件是支持中文格式的。 但是这种方式增加了tomcat的耦合性,web容器是用来运行web程序  的 还需要分出额外的精力去管理dubbo服务注册, 造成管理压力。同时对内存的占用也会加大,影响程序性能。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">
	<display-name>taotao-search</display-name>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	
	<!--初始化spring容器  --> 
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:spring/applicationContext-service.xml</param-value>
	</context-param>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	 
</web-app>

              (3):利用maven生成jar包通过Java-jar命令注册服务

              种方式可以将需要注册的服务单独放在服务器上进行管理。方便,有利于分布式应用的管理。利于分布式应用服务的扩展

<build>

   <resources>
    <resource>
        <!--生成的classes文件的路径,此文件夹中包含运行时的所有文件,可以不配置-->        
        <targetPath>${project.build.directory}/classes</targetPath>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <includes>
            <include>**/*.xml</include>
            <include>**/*.properties</include>
        </includes>
    </resource>
    <resource>
        <targetPath>${project.build.directory}/classes/META-INF/spring</targetPath>
        <directory>src/main/resources/spring</directory>
        <filtering>true</filtering>
        <includes>
            <include>applicationContext.xml</include>
        </includes>
    </resource>
    </resources>

    <!--下面的必须配置-->
    <plugins>
        <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <classesDirectory>target/classes/</classesDirectory>
<archive>
        <manifest>
        <mainClass>com.alibaba.dubbo.container.Main</mainClass>
    <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
                        <useUniqueVersions>false</useUniqueVersions>
        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
    </manifest>
        <manifestEntries>
            <Class-Path>.</Class-Path>
        </manifestEntries>
                </archive>
            </configuration>
        </plugin>
        <plugin>
    <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <type>jar</type>
                        <includeTypes>jar</includeTypes>
                        <outputDirectory>
                            ${project.build.directory}/lib
                        </outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    </build>

  1. DUBBO的访问过程(对外的链接是什么鬼)

  1. 什么是RPC

        答:本地过程调用,就是要像调用本地的函数一样去调远程函数 

--DUBBO下提供者XML配置(POM依赖要访问的jar)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
	http://code.alibabatech.com/schema/dubbo 
	http://code.alibabatech.com/schema/dubbo/dubbo.xsd
	http://www.springframework.org/schema/util 
	http://www.springframework.org/schema/util/spring-util-4.2.xsd">
	
	<!-- 配置包扫描器,扫描所有带@Service注解的类 -->
	<context:component-scan base-package="com.taotao.content.service"/>
	
	<!-- 发布dubbo服务 -->
	<!-- 提供方应用信息,用于计算依赖关系 -->
	<dubbo:application name="taotao-content"/>
	<!-- 注册中心的地址 -->
	<dubbo:registry protocol="zookeeper" address="192.168.0.104:2181"/>
	<!-- 用dubbo协议在20880端口暴露服务 -->
	<dubbo:protocol name="dubbo" port="20881"/>
	<!-- 声明需要暴露的服务接口 -->
	<dubbo:service interface="com.taotao.content.service.ContentCategoryService" ref="contentCategoryServiceImpl" timeout="300000"/>
	<dubbo:service interface="com.taotao.content.service.ContentService" ref="contentServiceImpl" timeout="300000"/>
</beans>

--DUBBO下消费者XML配置(POM依赖要访问的jar)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
        http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
	<!-- 引用dubbo服务 -->
	<dubbo:application name="taotao-portal-web"/>
	<dubbo:registry protocol="zookeeper" address="192.168.0.104:2181"/>	
	<dubbo:reference interface="com.taotao.content.service.ContentService" id="contentService" />
	
</beans>      

  1. 什么是Tree 和 B+Tree(不要和我说索引)

  2. 什么是反射

  3. MySql的存储类型(就是存储引擎,除了Myisam和innodb你还知道别的吗[吐了,谁TM记啊])

  4. 分布式情况下加锁(不要和我说分布式锁[那我和你说锤子呢在这])、

  5. GC的垃圾回收的过程

        答:大部分情况,对象都会首先在 Eden 区域分配,在一次新生代垃圾回收后,如果对象还存活,则会进入 s0 或者 s1,并且对象的年龄还会加 1(Eden 区->Survivor 区后对象的初始年龄变为 1),当它的年龄增加到一定程度(默认为 15 岁),就会被晋升到老年代中。对象晋升到老年代的年龄阈值,可以通过参数 -XX:MaxTenuringThreshold 来设置。