• 探花系统 Java笔试题


    1. package controller.com.tanhua.controller.domain;
    2. import org.junit.Test;
    3. import java.util.UUID;
    4. import java.util.concurrent.ExecutorService;
    5. import java.util.concurrent.SynchronousQueue;
    6. import java.util.concurrent.ThreadPoolExecutor;
    7. import java.util.concurrent.TimeUnit;
    8. /**
    9. * Created by Lenovo on 2023/10/10.
    10. */
    11. public class MainEntity {
    12. public static void main(String[] args) {
    13. }
    14. /**
    15. * 假设有一个银行网点,有多个窗口用于处理客户的业务。
    16. * 现在需要编写一个程序模拟该网点的业务处理过程,要求如下: 网点有 N 个窗口,用一个线程池管理这些窗口的线程。
    17. * 每个窗口可以同时处理多个客户的业务,但同时最多只能服务 K 个客户。
    18. * 客户可以在任意窗口进行业务办理,但需要等待窗口空闲后才能进行服务。
    19. * 当一个客户到达银行网点后,随机选择一个窗口进行排队等待服务,直到业务处理完成。
    20. * 在业务处理过程中,客户不能在多个窗口进行业务办理。
    21. * 请根据以上要求,编写一个 Java 程序实现银行网点的业务处理过程。
    22. *
    23. * 要求: 1、java代码实现 2、构造3组测试用例,可以执行通过 3、注释、日志齐全
    24. */
    25. @Test
    26. public void testBankBusiness(){
    27. System.out.println("hello test!");
    28. /**
    29. * N 个窗口 10个用户线程日志就绪运行
    30. */
    31. for (int i = 0; i < 10; i++) {
    32. new Thread(new Runnable() {
    33. @Override
    34. public void run() {
    35. Business business = new Business();
    36. String s = UUID.randomUUID().toString();
    37. business.setId(s);
    38. Customer customer = new Customer();
    39. String s1 = UUID.randomUUID().toString();
    40. customer.setId(s1);
    41. business.setName("用户"+customer.getId()+" 的银行业务id"+business.getId()+"办理完成!");
    42. System.out.println(business.getName());
    43. }
    44. }).start();
    45. }
    46. }
    47. @Test
    48. public void testBankBusinessThreadPool(){
    49. System.out.println("hello test");
    50. ExecutorService executorService = newCachedThreadPool();
    51. executorService.execute(new Runnable() {
    52. @Override
    53. public void run() {
    54. for (int i = 0; i < 10; i++) {
    55. Business business = new Business();
    56. String s = UUID.randomUUID().toString();
    57. business.setId(s);
    58. Customer customer = new Customer();
    59. String s1 = UUID.randomUUID().toString();
    60. customer.setId(s1);
    61. business.setName("用户"+customer.getId()+" 的银行业务id"+business.getId()+"办理完成!");
    62. System.out.println(business.getName());
    63. }
    64. }
    65. });
    66. }
    67. //创建CachedThreadPool
    68. public ExecutorService newCachedThreadPool() {
    69. return new ThreadPoolExecutor(0, Integer.MAX_VALUE,
    70. 60L, TimeUnit.SECONDS,
    71. new SynchronousQueue());
    72. }
    73. }
    74. package controller.com.tanhua.controller.domain;
    75. /**
    76. * Created by Lenovo on 2023/10/10.
    77. */
    78. public class Bank {
    79. private String id;
    80. private String name;
    81. public String getId() {
    82. return id;
    83. }
    84. public void setId(String id) {
    85. this.id = id;
    86. }
    87. public String getName() {
    88. return name;
    89. }
    90. public void setName(String name) {
    91. this.name = name;
    92. }
    93. }
    94. package controller.com.tanhua.controller.domain;
    95. /**
    96. * Created by Lenovo on 2023/10/10.
    97. */
    98. public class BankWindows {
    99. }
    100. package controller.com.tanhua.controller.domain;
    101. /**
    102. * Created by Lenovo on 2023/10/10.
    103. */
    104. public class Business {
    105. private String id;
    106. private String name;
    107. public String getId() {
    108. return id;
    109. }
    110. public void setId(String id) {
    111. this.id = id;
    112. }
    113. public String getName() {
    114. return name;
    115. }
    116. public void setName(String name) {
    117. this.name = name;
    118. }
    119. @Override
    120. public String toString() {
    121. return "Business{" +
    122. "id='" + id + '\'' +
    123. ", name='" + name + '\'' +
    124. '}';
    125. }
    126. }
    127. package controller.com.tanhua.controller.domain;
    128. /**
    129. * Created by Lenovo on 2023/10/10.
    130. */
    131. public class Customer {
    132. private String id;
    133. private String name;
    134. public String getId() {
    135. return id;
    136. }
    137. public void setId(String id) {
    138. this.id = id;
    139. }
    140. public String getName() {
    141. return name;
    142. }
    143. public void setName(String name) {
    144. this.name = name;
    145. }
    146. }

  • 相关阅读:
    Python 爬虫详解
    【数据结构与算法】链表的实现以及相关算法
    【Qt】添加第三方库的知识补充
    MASA Framework -- EventBus入门与设计
    C# 入坑JAVA 潜规则 大小写敏感文件名和类名 枚举等 入门系列2
    Rowset Class
    tsconfig编译属性isolatedModules的作用
    卷积神经网络预测数据值,一维卷积神经网络 keras
    Django后端开发——ORM
    jmeter实现webservice接口测试
  • 原文地址:https://blog.csdn.net/wanzhong_liao/article/details/133750736