【Nginx 源码学习】平滑重启,源码追踪,2024年最新java内存回收机制面试题

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Java开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024b (备注Java)
img

正文

pool->log = log;

cycle = ngx_pcalloc(pool, sizeof(ngx_cycle_t));

if (cycle == NULL) {

ngx_destroy_pool(pool);

return NULL;

}

cycle->pool = pool;

cycle->log = log;

cycle->old_cycle = old_cycle;

cycle->conf_prefix.len = old_cycle->conf_prefix.len;

cycle->conf_prefix.data = ngx_pstrdup(pool, &old_cycle->conf_prefix);

if (cycle->conf_prefix.data == NULL) {

ngx_destroy_pool(pool);

return NULL;

}

cycle->prefix.len = old_cycle->prefix.len;

cycle->prefix.data = ngx_pstrdup(pool, &old_cycle->prefix);

if (cycle->prefix.data == NULL) {

ngx_destroy_pool(pool);

return NULL;

}

cycle->conf_file.len = old_cycle->conf_file.len;

cycle->conf_file.data = ngx_pnalloc(pool, old_cycle->conf_file.len + 1);

if (cycle->conf_file.data == NULL) {

ngx_destroy_pool(pool);

return NULL;

}

ngx_cpystrn(cycle->conf_file.data, old_cycle->conf_file.data,

old_cycle->conf_file.len + 1);

cycle->conf_param.len = old_cycle->conf_param.len;

cycle->conf_param.data = ngx_pstrdup(pool, &old_cycle->conf_param);

if (cycle->conf_param.data == NULL) {

ngx_destroy_pool(pool);

return NULL;

}

n = old_cycle->paths.nelts ? old_cycle->paths.nelts : 10;

if (ngx_array_init(&cycle->paths, pool, n, sizeof(ngx_path_t *))

!= NGX_OK)

{

ngx_destroy_pool(pool);

return NULL;

}

ngx_memzero(cycle->paths.elts, n * sizeof(ngx_path_t *));

if (ngx_array_init(&cycle->config_dump, pool, 1, sizeof(ngx_conf_dump_t))

!= NGX_OK)

{

ngx_destroy_pool(pool);

return NULL;

}

ngx_rbtree_init(&cycle->config_dump_rbtree, &cycle->config_dump_sentinel,

ngx_str_rbtree_insert_value);

if (old_cycle->open_files.part.nelts) {

n = old_cycle->open_files.part.nelts;

for (part = old_cycle->open_files.part.next; part; part = part->next) {

n += part->nelts;

}

} else {

n = 20;

}

if (ngx_list_init(&cycle->open_files, pool, n, sizeof(ngx_open_file_t))

!= NGX_OK)

{

ngx_destroy_pool(pool);

return NULL;

}

if (old_cycle->shared_memory.part.nelts) {

n = old_cycle->shared_memory.part.nelts;

for (part = old_cycle->shared_memory.part.next; part; part = part->next)

{

n += part->nelts;

}

} else {

n = 1;

}

if (ngx_list_init(&cycle->shared_memory, pool, n, sizeof(ngx_shm_zone_t))

!= NGX_OK)

{

ngx_destroy_pool(pool);

return NULL;

}

n = old_cycle->listening.nelts ? old_cycle->listening.nelts : 10;

if (ngx_array_init(&cycle->listening, pool, n, sizeof(ngx_listening_t))

!= NGX_OK)

{

ngx_destroy_pool(pool);

return NULL;

}

ngx_memzero(cycle->listening.elts, n * sizeof(ngx_listening_t));

ngx_queue_init(&cycle->reusable_connections_queue);

cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module * sizeof(void *));

if (cycle->conf_ctx == NULL) {

ngx_destroy_pool(pool);

return NULL;

}

if (gethostname(hostname, NGX_MAXHOSTNAMELEN) == -1) {

ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, “gethostname() failed”);

ngx_destroy_pool(pool);

return NULL;

}

/* on Linux gethostname() silently truncates name that does not fit */

hostname[NGX_MAXHOSTNAMELEN - 1] = ‘\0’;

cycle->hostname.len = ngx_strlen(hostname);

cycle->hostname.data = ngx_pnalloc(pool, cycle->hostname.len);

if (cycle->hostname.data == NULL) {

ngx_destroy_pool(pool);

return NULL;

}

ngx_strlow(cycle->hostname.data, (u_char *) hostname, cycle->hostname.len);

if (ngx_cycle_modules(cycle) != NGX_OK) {

ngx_destroy_pool(pool);

return NULL;

}

for (i = 0; cycle->modules[i]; i++) {

if (cycle->modules[i]->type != NGX_CORE_MODULE) {

continue;

}

module = cycle->modules[i]->ctx;

if (module->create_conf) {

rv = module->create_conf(cycle);

if (rv == NULL) {

ngx_destroy_pool(pool);

return NULL;

}

cycle->conf_ctx[cycle->modules[i]->index] = rv;

}

}

senv = environ;

ngx_memzero(&conf, sizeof(ngx_conf_t));

/* STUB: init array ? */

conf.args = ngx_array_create(pool, 10, sizeof(ngx_str_t));

if (conf.args == NULL) {

ngx_destroy_pool(pool);

return NULL;

}

conf.temp_pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, log);

if (conf.temp_pool == NULL) {

ngx_destroy_pool(pool);

return NULL;

}

conf.ctx = cycle->conf_ctx;

conf.cycle = cycle;

conf.pool = pool;

conf.log = log;

conf.module_type = NGX_CORE_MODULE;

conf.cmd_type = NGX_MAIN_CONF;

#if 0

log->log_level = NGX_LOG_DEBUG_ALL;

#endif

if (ngx_conf_param(&conf) != NGX_CONF_OK) {

environ = senv;

ngx_destroy_cycle_pools(&conf);

return NULL;

}

if (ngx_conf_parse(&conf, &cycle->conf_file) != NGX_CONF_OK) {

environ = senv;

ngx_destroy_cycle_pools(&conf);

return NULL;

}

if (ngx_test_config && !ngx_quiet_mode) {

ngx_log_stderr(0, “the configuration file %s syntax is ok”,

cycle->conf_file.data);

}

for (i = 0; cycle->modules[i]; i++) {

if (cycle->modules[i]->type != NGX_CORE_MODULE) {

continue;

}

module = cycle->modules[i]->ctx;

if (module->init_conf) {

if (module->init_conf(cycle,

cycle->conf_ctx[cycle->modules[i]->index])

== NGX_CONF_ERROR)

{

environ = senv;

ngx_destroy_cycle_pools(&conf);

return NULL;

}

}

}

if (ngx_process == NGX_PROCESS_SIGNALLER) {

return cycle;

}

ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);

if (ngx_test_config) {

if (ngx_create_pidfile(&ccf->pid, log) != NGX_OK) {

goto failed;

}

} else if (!ngx_is_init_cycle(old_cycle)) {

/*

  • we do not create the pid file in the first ngx_init_cycle() call

  • because we need to write the demonized process pid

*/

old_ccf = (ngx_core_conf_t *) ngx_get_conf(old_cycle->conf_ctx,

ngx_core_module);

if (ccf->pid.len != old_ccf->pid.len

|| ngx_strcmp(ccf->pid.data, old_ccf->pid.data) != 0)

{

/* new pid file name */

if (ngx_create_pidfile(&ccf->pid, log) != NGX_OK) {

goto failed;

}

ngx_delete_pidfile(old_cycle);

}

}

if (ngx_test_lockfile(cycle->lock_file.data, log) != NGX_OK) {

goto failed;

}

if (ngx_create_paths(cycle, ccf->user) != NGX_OK) {

goto failed;

}

if (ngx_log_open_default(cycle) != NGX_OK) {

goto failed;

}

/* open the new files */

part = &cycle->open_files.part;

file = part->elts;

for (i = 0; /* void */ ; i++) {

if (i >= part->nelts) {

if (part->next == NULL) {

break;

}

part = part->next;

file = part->elts;

i = 0;

}

if (file[i].name.len == 0) {

continue;

}

file[i].fd = ngx_open_file(file[i].name.data,

NGX_FILE_APPEND,

NGX_FILE_CREATE_OR_OPEN,

NGX_FILE_DEFAULT_ACCESS);

ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,

“log: %p %d “%s””,

&file[i], file[i].fd, file[i].name.data);

if (file[i].fd == NGX_INVALID_FILE) {

ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,

ngx_open_file_n " “%s” failed",

file[i].name.data);

goto failed;

}

#if !(NGX_WIN32)

if (fcntl(file[i].fd, F_SETFD, FD_CLOEXEC) == -1) {

ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,

“fcntl(FD_CLOEXEC) “%s” failed”,

file[i].name.data);

goto failed;

}

#endif

}

cycle->log = &cycle->new_log;

pool->log = &cycle->new_log;

/* create shared memory */

part = &cycle->shared_memory.part;

shm_zone = part->elts;

for (i = 0; /* void */ ; i++) {

if (i >= part->nelts) {

if (part->next == NULL) {

break;

}

part = part->next;

shm_zone = part->elts;

i = 0;

}

if (shm_zone[i].shm.size == 0) {

ngx_log_error(NGX_LOG_EMERG, log, 0,

“zero size shared memory zone “%V””,

&shm_zone[i].shm.name);

goto failed;

}

shm_zone[i].shm.log = cycle->log;

opart = &old_cycle->shared_memory.part;

oshm_zone = opart->elts;

for (n = 0; /* void */ ; n++) {

if (n >= opart->nelts) {

if (opart->next == NULL) {

break;

}

opart = opart->next;

oshm_zone = opart->elts;

n = 0;

}

if (shm_zone[i].shm.name.len != oshm_zone[n].shm.name.len) {

continue;

}

if (ngx_strncmp(shm_zone[i].shm.name.data,

oshm_zone[n].shm.name.data,

shm_zone[i].shm.name.len)

!= 0)

{

continue;

}

if (shm_zone[i].tag == oshm_zone[n].tag

&& shm_zone[i].shm.size == oshm_zone[n].shm.size

&& !shm_zone[i].noreuse)

{

shm_zone[i].shm.addr = oshm_zone[n].shm.addr;

#if (NGX_WIN32)

shm_zone[i].shm.handle = oshm_zone[n].shm.handle;

#endif

if (shm_zone[i].init(&shm_zone[i], oshm_zone[n].data)

!= NGX_OK)

{

goto failed;

}

goto shm_zone_found;

}

break;

}

if (ngx_shm_alloc(&shm_zone[i].shm) != NGX_OK) {

goto failed;

}

if (ngx_init_zone_pool(cycle, &shm_zone[i]) != NGX_OK) {

goto failed;

}

if (shm_zone[i].init(&shm_zone[i], NULL) != NGX_OK) {

goto failed;

}

shm_zone_found:

continue;

}

/* handle the listening sockets */

if (old_cycle->listening.nelts) {

ls = old_cycle->listening.elts;

for (i = 0; i < old_cycle->listening.nelts; i++) {

ls[i].remain = 0;

}

nls = cycle->listening.elts;

for (n = 0; n < cycle->listening.nelts; n++) {

for (i = 0; i < old_cycle->listening.nelts; i++) {

if (ls[i].ignore) {

continue;

}

if (ls[i].remain) {

continue;

}

if (ls[i].type != nls[n].type) {

continue;

}

if (ngx_cmp_sockaddr(nls[n].sockaddr, nls[n].socklen,

ls[i].sockaddr, ls[i].socklen, 1)

== NGX_OK)

{

nls[n].fd = ls[i].fd;

nls[n].previous = &ls[i];

ls[i].remain = 1;

if (ls[i].backlog != nls[n].backlog) {

nls[n].listen = 1;

}

#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)

/*

  • FreeBSD, except the most recent versions,

  • could not remove accept filter

*/

nls[n].deferred_accept = ls[i].deferred_accept;

if (ls[i].accept_filter && nls[n].accept_filter) {

if (ngx_strcmp(ls[i].accept_filter,

nls[n].accept_filter)

!= 0)

{

nls[n].delete_deferred = 1;

nls[n].add_deferred = 1;

}

} else if (ls[i].accept_filter) {

nls[n].delete_deferred = 1;

} else if (nls[n].accept_filter) {

nls[n].add_deferred = 1;

}

#endif

#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)

if (ls[i].deferred_accept && !nls[n].deferred_accept) {

nls[n].delete_deferred = 1;

} else if (ls[i].deferred_accept != nls[n].deferred_accept)

{

nls[n].add_deferred = 1;

}

#endif

#if (NGX_HAVE_REUSEPORT)

if (nls[n].reuseport && !ls[i].reuseport) {

nls[n].add_reuseport = 1;

}

#endif

break;

}

}

if (nls[n].fd == (ngx_socket_t) -1) {

nls[n].open = 1;

#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)

if (nls[n].accept_filter) {

nls[n].add_deferred = 1;

}

#endif

#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)

if (nls[n].deferred_accept) {

nls[n].add_deferred = 1;

}

#endif

}

}

} else {

ls = cycle->listening.elts;

for (i = 0; i < cycle->listening.nelts; i++) {

ls[i].open = 1;

#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)

if (ls[i].accept_filter) {

ls[i].add_deferred = 1;

}

#endif

#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)

if (ls[i].deferred_accept) {

ls[i].add_deferred = 1;

}

#endif

}

}

if (ngx_open_listening_sockets(cycle) != NGX_OK) {

goto failed;

}

if (!ngx_test_config) {

ngx_configure_listening_sockets(cycle);

}

/* commit the new cycle configuration */

if (!ngx_use_stderr) {

(void) ngx_log_redirect_stderr(cycle);

}

pool->log = cycle->log;

if (ngx_init_modules(cycle) != NGX_OK) {

/* fatal */

exit(1);

}

/* close and delete stuff that lefts from an old cycle */

/* free the unnecessary shared memory */

opart = &old_cycle->shared_memory.part;

oshm_zone = opart->elts;

for (i = 0; /* void */ ; i++) {

if (i >= opart->nelts) {

if (opart->next == NULL) {

goto old_shm_zone_done;

}

opart = opart->next;

oshm_zone = opart->elts;

i = 0;

}

part = &cycle->shared_memory.part;

shm_zone = part->elts;

for (n = 0; /* void */ ; n++) {

if (n >= part->nelts) {

if (part->next == NULL) {

break;

}

part = part->next;

shm_zone = part->elts;

n = 0;

}

if (oshm_zone[i].shm.name.len != shm_zone[n].shm.name.len) {

continue;

}

if (ngx_strncmp(oshm_zone[i].shm.name.data,

shm_zone[n].shm.name.data,

oshm_zone[i].shm.name.len)

!= 0)

{

continue;

}

if (oshm_zone[i].tag == shm_zone[n].tag

&& oshm_zone[i].shm.size == shm_zone[n].shm.size

&& !oshm_zone[i].noreuse)

{

goto live_shm_zone;

}

break;

}

ngx_shm_free(&oshm_zone[i].shm);

live_shm_zone:

continue;

}

old_shm_zone_done:

写在最后

作为一名即将求职的程序员,面对一个可能跟近些年非常不同的 2019 年,你的就业机会和风口会出现在哪里?在这种新环境下,工作应该选择大厂还是小公司?已有几年工作经验的老兵,又应该如何保持和提升自身竞争力,转被动为主动?

就目前大环境来看,跳槽成功的难度比往年高很多。一个明显的感受:今年的面试,无论一面还是二面,都很考验Java程序员的技术功底。

最近我整理了一份复习用的面试题及面试高频的考点题及技术点梳理成一份“Java经典面试问题(含答案解析).pdf和一份网上搜集的“Java程序员面试笔试真题库.pdf”(实际上比预期多花了不少精力),包含分布式架构、高可扩展、高性能、高并发、Jvm性能调优、Spring,MyBatis,Nginx源码分析,Redis,ActiveMQ、Mycat、Netty、Kafka、Mysql、Zookeeper、Tomcat、Docker、Dubbo、Nginx等多个知识点高级进阶干货!

由于篇幅有限,为了方便大家观看,这里以图片的形式给大家展示部分的目录和答案截图!

Java经典面试问题(含答案解析)

阿里巴巴技术笔试心得

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Java)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
0)

{

continue;

}

if (oshm_zone[i].tag == shm_zone[n].tag

&& oshm_zone[i].shm.size == shm_zone[n].shm.size

&& !oshm_zone[i].noreuse)

{

goto live_shm_zone;

}

break;

}

ngx_shm_free(&oshm_zone[i].shm);

live_shm_zone:

continue;

}

old_shm_zone_done:

写在最后

作为一名即将求职的程序员,面对一个可能跟近些年非常不同的 2019 年,你的就业机会和风口会出现在哪里?在这种新环境下,工作应该选择大厂还是小公司?已有几年工作经验的老兵,又应该如何保持和提升自身竞争力,转被动为主动?

就目前大环境来看,跳槽成功的难度比往年高很多。一个明显的感受:今年的面试,无论一面还是二面,都很考验Java程序员的技术功底。

最近我整理了一份复习用的面试题及面试高频的考点题及技术点梳理成一份“Java经典面试问题(含答案解析).pdf和一份网上搜集的“Java程序员面试笔试真题库.pdf”(实际上比预期多花了不少精力),包含分布式架构、高可扩展、高性能、高并发、Jvm性能调优、Spring,MyBatis,Nginx源码分析,Redis,ActiveMQ、Mycat、Netty、Kafka、Mysql、Zookeeper、Tomcat、Docker、Dubbo、Nginx等多个知识点高级进阶干货!

由于篇幅有限,为了方便大家观看,这里以图片的形式给大家展示部分的目录和答案截图!
[外链图片转存中…(img-37mU9O5C-1713437838047)]

Java经典面试问题(含答案解析)

[外链图片转存中…(img-pXBOxed0-1713437838048)]

阿里巴巴技术笔试心得

[外链图片转存中…(img-qjrzDE0c-1713437838048)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Java)
[外链图片转存中…(img-EP5iSIIx-1713437838049)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 15
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值